你好!
我目前在Windows 7上使用Selenium和Python,我尝试将Chrome webdriver用于隐藏功能--no-startup-window
。安装Chrome(x86)后,在路径C:\Python27\Scripts\
上复制了chromedriver.exe并将其添加到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
,因此我还将chromedriver.exe复制到了他的Scripts
文件夹中。有关这个问题的任何想法吗?
答案 0 :(得分:2)
例如将chormedriver.exe文件放在驱动器C:\上并使用:
variablename=thevalue