2014-09-22 97 views
2

我试图找到答案,不能,现在我问自己。尝试启动与硒webdriver Linux上的铬驱动程序

我写了简单的测试

from selenium import webdriver 

driver = webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver") 
driver.get("http://www.python.org") 
driver.close() 

比我回溯

> [email protected]:~/workspace$ python testchrome.py Traceback 
> (most recent call last): File "testchrome.py", line 6, in <module> 
> driver = 
> webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver") 
> File 
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", 
> line 65, in __init__ keep_alive=True) File 
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", 
> line 73, in __init__ self.start_session(desired_capabilities, 
> browser_profile) File 
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", 
> line 121, in start_session 'desiredCapabilities': 
> desired_capabilities, File 
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", 
> line 173, in execute self.error_handler.check_response(response) File 
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", 
> line 166, in check_response raise exception_class(message, screen, 
> stacktrace) selenium.common.exceptions.WebDriverException: Message: 
> u'unknown error: Chrome failed to start: exited abnormally\n (Driver 
> info: chromedriver=2.10.267517,platform=Linux 3.13.0-35-generic x86)' 

我有最新版本的chromedriver 10,最新chromium,最新selenium webdriver。 而这一切都在我开始的Xubuntu

Linux版本的3.13.0-35泛型(buildd @ roseapple)(gcc版本4.8.2(Ubuntu的4.8.2-19ubuntu1))#62 Ubuntu的SMP周五八月15 1点58分01秒UTC 2014

请帮我:(

回答

0

2.10.267517是不是最新的版本。

$ chromedriver --version 
ChromeDriver 2.10.267518 

通过以上版本,Pytho 2.7.6,你的代码运行良好。 (除了我修改了chromedriver路径)

仅供参考,这里有UNAME对我的Ubuntu:

$ uname -a 
Linux jmlee12 3.13.0-36-generiC#63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 
$ python -V 
Python 2.7.6 
+0

这很好,但我可以在哪里找到下一个版本? – tranter 2014-09-23 11:07:09

+0

@tranter,这里:http://chromedriver.storage.googleapis.com/index.html您可以在这里找到当前最新版本:http://chromedriver.storage.googleapis.com/index.html?path=2.10/ – falsetru 2014-09-23 11:09:01

+0

我在这里尝试,但10个版本是17,而不是18个。它是32位版本,你能分享我这个东西吗? – tranter 2014-09-23 12:51:00

10

对于Linux用户:

启动显示之前启动浏览器。欲了解更多信息请点击here

from selenium import webdriver 
from pyvirtualdisplay import Display 
# Add following 2 line before start the Chrome 
display = Display(visible=0, size=(800, 800)) 
display.start() 
driver = webdriver.Chrome() 
driver.get("http://www.google.com") 
driver.quit() 
display.stop()