在chrome中运行Selenium WebDriver python绑定
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在chrome中运行Selenium WebDriver python绑定,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2405字,纯文字阅读大概需要4分钟。
内容图文
![在chrome中运行Selenium WebDriver python绑定](/upload/InfoBanner/zyjiaocheng/716/521b2c6f7651443399067329144f830d.jpg)
我在使用Selenium时遇到了问题.对于我的项目,我必须使用Chrome.但是,在使用Selenium启动它后,我无法连接到该浏览器.
出于某种原因,Selenium无法单独找到Chrome.当我尝试在不包含路径的情况下启动Chrome时会发生这种情况:
Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome() # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 58, in start
and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path. Please download from http://code.google.com/p/selenium/downloads/list and read up at http://code.google.com/p/selenium/wiki/ChromeDriver'
为了解决这个问题,我在启动Chrome的代码中包含了Chromium路径.但是,解释器无法找到要连接的套接字:
Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome('/usr/bin/chromium') # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 64, in start
raise WebDriverException("Can not connect to the ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the ChromeDriver'
我也尝试通过启动chrome来解决问题:
chromium --remote-shell-port=9222
但是,这也不起作用.
PS.这是关于我的系统的一些信息:
www-client: chromium 15.0.874.121 dev-lang: python 2.7.2-r3 Selenium 2.11.1 OS: GNU/Linux Gentoo Kernel 3.1.0-gentoo-r1
解决方法:
您需要确保独立的ChromeDriver二进制文件(与Chrome浏览器二进制文件不同)位于您的路径中,或者在webdriver.chrome.driver环境变量中可用.
有关如何连线的详细信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver.
编辑:
是的,似乎是Python绑定中的一个错误,从路径或环境变量中读取chromedriver二进制文件.似乎chromedriver不在您的路径中,您必须将其作为参数传递给构造函数.
import os
from selenium import webdriver
chromedriver = "/Users/adam/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("https://stackoverflow.com")
driver.quit()
内容总结
以上是互联网集市为您收集整理的在chrome中运行Selenium WebDriver python绑定全部内容,希望文章能够帮你解决在chrome中运行Selenium WebDriver python绑定所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。