【问题标题】:Clear caches in Chrome browser using selenium Chrome driver使用 selenium Chrome 驱动程序清除 Chrome 浏览器中的缓存
【发布时间】:2022-03-23 22:05:02
【问题描述】:

我正在使用 Python 3 和 Selenium 进行编码。我想在chrome中自动清除缓存,时间无关紧要。

这是我目前的解决方案:

driver.get('chrome://settings/clearBrowserData')
time.sleep(3)
driver.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER)
time.sleep(10)

然而,这个解决方案没有点击“删除数据”按钮,我不知道为什么......

Chromedriver 版本为 85.0.4183.87 和 Selenium 3.141。

【问题讨论】:

  • 能否提供minimal reproducible example chrome 和驱动的版本是什么?
  • 基于您的 chrome 版本,我相信 this comment 解释了为什么这不起作用。
  • Chromedriver 版本为 85.0.4183.87 和 Selenium 3.141。问题是这一行: driver.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER) 我没有收到错误消息,但脚本只是没有单击按钮。
  • 引用上述评论:“此选择器不再返回 81.0.4 中的任何元素”
  • 是的,我读过。直到昨天,这些代码行仍在工作。 :(

标签: python python-3.x selenium selenium-chromedriver


【解决方案1】:

您可以使用操作 + 键盘键来访问此按钮(Tab 和 Enter)。您需要按 Tab 7 次,然后按 Enter。所以,使用: TabX(7);进入();。适合我(C#)。

    public void TabX(int valor)
    {
        for (int i = 0; i < valor; i++)
        {
            Actions act = new Actions(driver);
            act.SendKeys(Keys.Tab).Build().Perform();
        }
    }

    public void Enter()
    {
        Actions act = new Actions(driver);
        act.SendKeys(Keys.Enter).Build().Perform();
    }

【讨论】:

    猜你喜欢
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2018-09-11
    • 2015-07-11
    • 2011-10-23
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多