我在使用 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'
我还尝试用以下软件来解决这个问题:
chromium --remote-shell-port=9222
However, this did not work either.
PS. Here's some information about my system:
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