3

So I am only a beginner on my path to learning vba and selenium. I was trying to click a button in the chrome settings to disable images, however I couldn't figure out how to achieve this.

I used the following url:

chrome://settings/content/images

And then tried to click on the toggle button with

driver.FindElementByCss("#button").Click

However, I always get the error "Element not visible".

So I figured out it has to be because of the "#shadow root" in the html code. However I have no idea what that means or how to figure out a way to access the element... any tips on how I could figure out a way to solve this are very appreciated :-)

Thank you for your help!

S Meaden
  • 8,050
  • 3
  • 34
  • 65
Websitewichtel
  • 125
  • 3
  • 10
  • @QHarr yes exactly! – Websitewichtel Jul 21 '18 at 21:33
  • on what web page? – S Meaden Jul 21 '18 at 21:50
  • Some web pages have buttons that are images. And you have just prevented their download. – S Meaden Jul 21 '18 at 21:51
  • this is the link: chrome://settings/content/images – Websitewichtel Jul 21 '18 at 22:18
  • its under chrome settings -> advanced -> content -> images – Websitewichtel Jul 21 '18 at 22:19
  • You need more than to access just the element I'm afraid. Shadow root applies to shadow dom but that is not the issue at play here. The element can be selected but how to trigger the appropriate action - still scratching my head.... – QHarr Jul 21 '18 at 22:19
  • As I am also interested in learning as much as I can, can you explain a little bit about shadow dom or maybe point me to where I can find out more about it. That would be great – Websitewichtel Jul 22 '18 at 05:00
  • Your element can be selected with html.querySelector("#control").document.getElementById("button") but I cannot find the right way to handle the object. The closest was Call .ExecuteScript("arguments[0].click();", element) , where element was the object variable holding the element of interest.....But no dice.... I tried clicking, fireevent and setting the attribute values for the aria for the object above amongst other things. – QHarr Jul 22 '18 at 08:27
  • https://www.webcomponents.org/community/articles/introduction-to-shadow-dom , https://stackoverflow.com/questions/34119639/what-is-shadow-root and https://www.w3.org/TR/shadow-dom/ – QHarr Jul 22 '18 at 08:31

1 Answers1

2

This doesn't answer the question with regards to how you can actually click the button, but it does get the the result you're looking for ;)

Sub toggle_images()

Dim bot As New WebDriver
bot.Start "chrome", "chrome://settings/content/images"
bot.Get "/"

For i = 1 To 21
    bot.SendKeys bot.Keys.Tab
Next i

bot.SendKeys bot.Keys.Enter

End Sub
newuser2967
  • 316
  • 1
  • 4
  • 15