2016-09-13 81 views
0

您好!Chrome网络驱动器无法连接到Windows上的服务chromedriver.exe

我目前在Windows 7上使用Selenium和Python,我尝试使用Chrome webdriver作为隐藏函数--no-startup-window。我安装了Chrome(86),复制chromedriver.exe后的路径C:\Python27\Scripts\,并添加它的PATH环境,我想通过下面的代码来启动它:

opt = Options() 
opt.add_argument("--no-startup-window") 

driver = webdriver.Chrome(chrome_options=opt) 

不过,我有以下错误,当我执行它:

(env) c:\opt\project\auto\>python program_test.py 
Traceback (most recent call last): 
    File "program_test.py", line 234, in <module> 
    main() 
    File "program_test.py", line 36, in main 
    initChromeWebDriver() 
    File "c:\opt\project\auto\common\driver.py", line 32, in initChromeWebDriver 
    service_log_path=) 
    File "c:\opt\project\auto\lib\site-packages\selenium\webdriver\chrome\webdriver.p 
y", line 61, in __init__ 
    self.service.start() 
    File "c:\opt\project\auto\lib\site-packages\selenium\webdriver\common\service.py" 
, line 88, in start 
    raise WebDriverException("Can not connect to the Service %s" % self.path) 
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver 

注:我目前使用virtualenv还,所以我也复制了他Scripts文件夹中的chromedriver.exe。有关这个问题的任何想法吗?

回答

2

第一,而不是使用()的选项方法,你应该使用webdriver.ChromeOptions()方法有你想要的结果,其次,你应该指定安装在你电脑上的Chromedriver的路径。

例如把chormedriver.exe文件在驱动器C:\和使用:

chrome_options = webdriver.ChromeOptions() 
    chrome_options.add_argument("--no-startup-window") 
    driver = webdriver.Chrome("C:\\chromedriver.exe", chrome_options=chrome_options) 

    driver.get("www.google.com") 
+0

确定这一这里解决了我的第一个问题,但是我现在有一个'未知错误:铬失败时,我用它来start' '--no-startup-window'。此外,Chrome在我评论此选项时正在启动。我为错误更新了我的帖子。 – toshiro92

+0

@ toshiro92你为什么要在没有启动窗口的情况下打开chrome,你能解释一下吗? – Soorena

+0

我只是需要它来避免一些错误的手动操作。 – toshiro92

相关问题