硒+;Python:CSS选择器--NoTouchElement错误
我正在编写一个使用Selenium的代码。 为了测试硒+;Python:CSS选择器--NoTouchElement错误,python,python-3.x,selenium,webdriver,selenium-chromedriver,Python,Python 3.x,Selenium,Webdriver,Selenium Chromedriver,我正在编写一个使用Selenium的代码。 为了测试find\u element\u by\u css\u selector函数,我编写了以下代码: self.browserProfile = webdriver.ChromeOptions() self.browserProfile.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'}) self.browser = webdriver.Chrome('Ch
find\u element\u by\u css\u 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无法通过找到所需的WebElement,您已使用该WebElement
相关的HTML将帮助我们更好地分析您的问题。但是,您的主要问题是所使用的二进制文件版本之间的不兼容,如下所示:
- 您使用的是chromedriver=2.25
- 的发行说明明确提到以下内容:
- 您使用的是chrome=70.0
- 的发行说明明确提到以下内容:
- 我们不知道您的Selenium客户端版本
- 保持硒升级到当前水平
- 将ChromeDriver升级到当前级别
- 将Chrome版本保持在Chrome v71-73级别之间。()
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
- 执行
@测试
- 始终在
方法中调用tearDown(){}
,以优雅地关闭和销毁Web驱动程序和Web客户端实例driver.quit()