Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
硒+;Python:CSS选择器--NoTouchElement错误_Python_Python 3.x_Selenium_Webdriver_Selenium Chromedriver - Fatal编程技术网

硒+;Python:CSS选择器--NoTouchElement错误

硒+;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

我正在编写一个使用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('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 v53-55

  • 您使用的是chrome=70.0
  • 的发行说明明确提到以下内容:
支持Chrome v70-72

  • 我们不知道您的Selenium客户端版本
因此,ChromeDriver v2.25和Chrome浏览器v70.0之间存在明显的不匹配

解决方案
  • 保持硒升级到当前水平
  • 将ChromeDriver升级到当前级别
  • 将Chrome版本保持在Chrome v71-73级别之间。()
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
  • 执行
    @测试
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

您能显示页面吗?似乎定位器错误,请共享此元素的页面源代码。请共享您的HTML。该按钮可能添加得很晚。我不确定为什么有人否决了您。您向OP解释了问题以及解决方案的多个方面,让OP自己解决。此解决方案有效。我把chromedriver更新到了最新版本,现在它工作得很顺利,谢谢你,好消息!!!我确信版本不兼容的实际问题,as@NoSplitSherlock的支持给了我们信心,我们正朝着正确的方向解决您的问题。