gpt4 book ai didi

python - Selenium +Python : CSS Selector -- NoSuchElement error

转载 作者:行者123 更新时间:2023-12-01 08:16:11 25 4
gpt4 key购买 nike

我正在编写一个使用 Selenium 的代码。为了测试 find_element_by_css_selector 函数,我编写了以下代码:

self.browserProfile = webdriver.ChromeOptions()
self.browserProfile.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
self.browser = webdriver.Chrome('Chrome_Driver/chromedriver', chrome_options=self.browserProfile)
self.email = email
self.password = password
self.browser.get('http://samplePage.html')
inputs = self.browser.find_element_by_css_selector('button')
print(inputs)

但我收到以下错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button"}
(Session info: chrome=70.0.3538.77)
(Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.15.0-45-generic x86_64)

如何解决这个错误?chromedriver 和所有必需的依赖项均已满足我正在运行 python 3.6。

最佳答案

此错误消息...

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button"}

...暗示 ChromeDriver 无法通过 Locator Strategy 找到所需的 WebElement您已经使用过。

相关的 HTML 可以帮助我们更好地分析您的问题。但是,您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:

  • 您正在使用 chromedriver=2.25
  • chromedriver=2.25 的发行说明明确提到以下内容:

Supports Chrome v53-55

Supports Chrome v70-72

  • 我们未知您的Selenium 客户端版本。

因此,ChromeDriver v2.25Chrome 浏览器 v70.0 之间存在明显的不匹配

解决方案

  • Selenium保持升级到当前级别 Version 3.141.59 .
  • ChromeDriver升级到当前的ChromeDriver v2.46级别。
  • Chrome 版本保持在 Chrome v71-73 级别之间。 (as per ChromeDriver v2.46 release notes)
  • 通过 IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
  • 如果您的基本网络客户端版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和已发布版本的Web 客户端
  • 执行您的@Test
  • 始终在 tearDown(){} 方法中调用 driver.quit() 来关闭和销毁 WebDriverWeb Client 优雅地实例化。

关于python - Selenium +Python : CSS Selector -- NoSuchElement error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54968544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com