Py学习  »  Python

Selenium Python:无法清除chrome浏览器缓存

VISHVAMBRUTHJAVAGALTHIMMEGOWDA • 6 年前 • 4137 次点击  

导航到chrome://settings/clear browser data后,单击下面的“清除数据”按钮,尝试清除chrome浏览器缓存。但我无法点击“清除数据”按钮。请告知。

enter image description here

我用的是:

操作系统: 赢得10 pro 64位

python版本: 3.6.1条

Chrome版本: 74.0.3729.169(官方版本)(64位)

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])
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51337
文章 [ 2 ]  |  最新文章 6 年前
DebanjanB
Reply   •   1 楼
DebanjanB    6 年前

在行尾添加“.click()”:

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

driver.find_element_by_xpath("//*[@id="clearBrowsingDataConfirm"]").click()
supputuri
Reply   •   2 楼
supputuri    6 年前

下面是javascript返回clearButton元素,然后使用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()

检查我的答案 Here 更详细的解释。