Python Chrome webdriver无法连接到Windows上的chromedriver.exe服务

Python Chrome webdriver无法连接到Windows上的chromedriver.exe服务,python,google-chrome,selenium,selenium-webdriver,webdriver,Python,Google Chrome,Selenium,Selenium Webdriver,Webdriver,你好! 我目前正在Windows 7上使用Selenium和Python,并尝试将Chrome webdriver用于隐藏函数--无启动窗口。安装Chrome(x86)后,在路径C:\Python27\Scripts\上复制了chromedriver.exe并将其添加到路径环境中,我尝试通过以下代码启动它: opt = Options() opt.add_argument("--no-startup-window") driver = webdriver.Chrome(chrome_optio

你好!

我目前正在Windows 7上使用Selenium和Python,并尝试将Chrome webdriver用于隐藏函数
--无启动窗口
。安装Chrome(x86)后,在路径
C:\Python27\Scripts\
上复制了chromedriver.exe并将其添加到路径环境中,我尝试通过以下代码启动它:

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
(env)c:\opt\project\auto\>python程序\u test.py
回溯(最近一次呼叫最后一次):
文件“program_test.py”,第234行,在
main()
文件“program_test.py”,第36行,在main中
initChromeWebDriver()
文件“c:\opt\project\auto\common\driver.py”,第32行,位于initChromeWebDriver中
服务日志路径=)
文件“c:\opt\project\auto\lib\site packages\selenium\webdriver\chrome\webdriver.p
y“,第61行,初始__
self.service.start()
文件“c:\opt\project\auto\lib\site packages\selenium\webdriver\common\service.py”
,第88行,开始
引发WebDriverException(“无法连接到服务%s”%self.path)
selenium.common.exceptions.WebDriverException:消息:无法连接到服务chromedriver

注意:我目前也在使用一个
virtualenv
,因此我还将chromedriver.exe复制到了他的
Scripts
文件夹中。对这里的问题有什么想法吗?

首先,不要使用选项()方法,你应该使用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")

首先,不要使用Options()方法,而应该使用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")

好的,这解决了我的第一个问题,但是我现在有一个未知错误:当我使用
--无启动窗口时,Chrome无法启动。另外,当我评论这个选项时,Chrome正在启动。我更新了帖子中的错误。@toshiro92您为什么要在没有启动窗口的情况下打开chrome,您能解释一下吗?好的,这解决了我在这里遇到的第一个问题,但是我现在有一个
未知错误:当我使用
--没有启动窗口时,chrome无法启动。另外,当我评论这个选项时,Chrome正在启动。我更新了帖子中的错误。@toshiro92为什么要在没有启动窗口的情况下打开chrome,你能解释一下吗?