-1

I'm trying to clear chrome browser cache by click on the 'Clear data' button below after navigating to chrome://settings/clearBrowserData. But I'm unable to click on the 'Clear data' button. Please advise.

enter image description here

I'm using:

Operating System: Win 10 pro 64bit

python version: 3.6.1

Chrome Version: 74.0.3729.169 (Official Build) (64-bit)

def clear_current_session(self):

    # Opens a new tab
    self.driver.execute_script("window.open()")

    # Switch to the newly opened tab
    self.driver.switch_to.window(self.driver.window_handles[1])

    # Navigate to new URL in new tab
    self.driver.get("chrome://settings/clearBrowserData")

    #Click on the Clear data button
    self.driver.find_element_by_css_selector("* /deep/ #clearBrowsingDataConfirm").click()

    self.driver.implicitly_wait(60)

    # Switch to original tab
    self.driver.switch_to.window(self.driver.window_handles[0])
VISHVAMBRUTH J T
  • 602
  • 4
  • 14
  • 29

2 Answers2

2

Below is the script where javascript will return the clearButton element and then clicks using python selenium.

clearButton = driver.execute_script("return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-section > settings-privacy-page').shadowRoot.querySelector('settings-clear-browsing-data-dialog').shadowRoot.querySelector('#clearBrowsingDataDialog').querySelector('#clearBrowsingDataConfirm')")
#click on the clear button now
clearButton.click()

Check my answer Here for more detailed explanation.

supputuri
  • 13,644
  • 2
  • 21
  • 39
0

Add the ".click()" at the end of the line:

self.driver.find_element_by_css_selector("* /deep/ #clearBrowsingDataConfirm").click()

or

driver.find_element_by_xpath("//*[@id="clearBrowsingDataConfirm"]").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ferdbugs
  • 19
  • 5