首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >chromedriver.exe无法连接到Windows上的服务chromedriver.exe

chromedriver.exe无法连接到Windows上的服务chromedriver.exe
EN

Stack Overflow用户
提问于 2016-09-13 20:04:41
回答 1查看 3.1K关注 0票数 0

您好!

目前,我在Windows 7上使用7,并尝试使用函数--no-startup-window。在安装Chrome (x86)、在path C:\Python27\Scripts\上复制chromedriver.exe并在PATH环境中添加它之后,我尝试通过以下代码启动它:

代码语言:javascript
复制
opt = Options()
opt.add_argument("--no-startup-window")

driver = webdriver.Chrome(chrome_options=opt)

但是,当我执行它时,我有以下错误:

代码语言:javascript
复制
(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。对这件事有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-13 20:10:01

首先,您应该使用webdriver.ChromeOptions()方法来获得所需的结果,而不是使用Options()方法,其次,您应该指定安装在计算机上的Chromedrier的路径。

例如,将chormedriver.exe文件放在驱动器C:\上,然后使用:

代码语言:javascript
复制
    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")
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39478170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档