Python selenium Python selenium selenium selenium

Python selenium


driver.find_element_by_xpath is just looking for the checkbox and returning it as WebElement. You want to click on it to unchecked it

driver.find_element_by_xpath("""//*[@id="delete-browsing-history-checkbox"]""").click()

Also, you forgot apostrophes in the first xpath after @id=. It should be like in the example above.

Edit

You can try locating the checkbox by id

 driver.find_element_by_id("delete-browsing-history-checkbox").click()

Edit 2

The checkbox are inside iframe. You need to switch to it first

driver.switch_to.frame("settings") # switch to the iframe by name attribute# driver.switch_to.frame(driver.find_element_by_name("settings")) # should also workdriver.find_element_by_id("delete-browsing-history-checkbox").click()driver.switch_to.default_content() # switch back to main window


Can you add to your question what you get as body from selenium?

 driver.get("chrome://settings/clearBrowserData") driver.page_source

If I check the source code in Google Chrome of this page I get:

view-source:chrome://chrome/settings/clearBrowserData

<body><div id="navigation"><iframe src="chrome://uber-frame/" name="chrome" role="presentation"></iframe></div><div class="iframe-container"    i18n-values="id:historyHost; data-url:historyFrameURL;"    data-favicon="IDR_HISTORY_FAVICON"></div><div class="iframe-container"    i18n-values="id:extensionsHost; data-url:extensionsFrameURL;"    data-favicon="IDR_EXTENSIONS_FAVICON"></div><div class="iframe-container"    i18n-values="id:settingsHost; data-url:settingsFrameURL;"    data-favicon="IDR_SETTINGS_FAVICON"></div><div class="iframe-container"    i18n-values="id:helpHost; data-url:helpFrameURL;"    data-favicon="IDR_PRODUCT_LOGO_16"></div><script src="chrome://chrome/strings.js"></script><script src="chrome://resources/js/i18n_template.js"></script></body>

It might be necessary to find another way to do it, if your driver cannot see this node.

Edit

In the source code you posted as page_source returned from selenium, there isn't the node you are trying to find.


After doing a find_element_by... all you get is the element. You also need to have a .click() on that element.

Either:

elem = driver.find_element_by_xpath("""//*[@id=delete-browsing-history-checkbox"]""")elem.click()

or:

driver.find_element_by_xpath("""//*[@id=delete-browsing-history-checkbox"]""").click()

Btw, you could just use find_element_by_id("delete-browsing-history-checkbox") in your case.

Also, I don't think selenium works on non-web pages. So chrome settings and Firefox's about:config pages (for example) don't work with selenium.