好吧,这在chrome和Firefox中都可以。我有:
$ ls -l /usr/local/bin/
-rwxr-xr-x 1 root root 11808880 Nov 26 22:04 chromedriver
-rwxr-xr-x 1 root root 6162368 Nov 26 18:08 geckodriver
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
我正在python2.7下运行此程序,我是通过pacman的pip2,python2.7安装selenium的(还有其他我还没有安装到python 3的库,请重点关注)。在idle2中,我得到:
>>> from selenium import webdriver
>>> browser = webdriver.Chrome()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
browser = webdriver.Chrome()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service chromedriver
>>> browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
browser = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service /usr/local/bin/chromedriver
>>> import selenium.webdriver.chrome.service as service
>>> s = service.Service('/usr/local/bin/chromedriver')
>>> s.start()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
s.start()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
WebDriverException: Message: Can not connect to the Service /usr/local/bin/chromedriver
我也尝试过,将一个版本的chromedriver放入我的主目录中并指向它,然后将所有权更改为我自己,这都是不可行的,壁虎驱动程序存在相同的问题,相同的错误,我非常困惑老公在这里,我做到了:
>>> browser = webdriver.Chrome(executable_path="/home/me/chromedriver", service_args=["--verbose", "--log-path=/home/me/chrome.log"])
相同,错误,并且它生成了一个空的日志文件,它从未生成过一个空文件,并且geckodriver.log始终为空。