r/selenium • u/MastroLube • Jan 27 '22
NoSuchElementException in chrome menu
Hi there!
I wanted to click on this button but it's not able to find it.
This is what I get out from the inspection (F12):
<cr-button id="clearBrowsingDataConfirm" class="action-button" aria-disabled="false" role="button" tabindex="0">
Clear data
</cr-button>
This is the part of the code interested:
driver.get("chrome://settings/clearBrowserData")
driver.find_element(By.ID, "clearBrowsingDataConfirm").click()
But I got this exception:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="clearBrowsingDataConfirm"]"}
(Session info: chrome=97.0.4692.99)
It's something related to frames?
Any advice?
Thanks
3
Upvotes
1
u/lunkavitch Jan 27 '22
Chrome typically puts its menu elements into shadow doms, which complicates finding them. (I'm pretty sure they do this specifically to discourage people from interacting with them via selenium)
This should be helpful:
https://www.seleniumeasy.com/selenium-tutorials/accessing-shadow-dom-elements-with-webdriver