Selenium打开浏览器但返回错误

问题描述 投票:0回答:1

在运行此代码时

from selenium import webdriver
driver = webdriver.Chrome("/usr/bin/google-chrome")

使用新选项卡打开浏览器后退出此错误

File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 0

之后我无法使用驱动变量,因为它返回一个NameError。

我用pip安装了selenium,我使用的是python 3.5.3。

Edit 1:

我忘了提到我正在使用Ubuntu 17.04 zesty

google-chrome selenium-webdriver python-3.5 ubuntu-17.04
1个回答
0
投票

当您使用Selenium 3.x.x以及最近的Google Chrome浏览器时,您必须从chromedriver.exe下载this location将它放在您的系统中,并通过chromedriver参数提及executable_path二进制文件的绝对位置,如下所示:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
© www.soinside.com 2019 - 2024. All rights reserved.