您好!
目前,我在Windows 7上使用7,并尝试使用函数--no-startup-window。在安装Chrome (x86)、在path 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,所以我也在他的Scripts文件夹上复制了chromedriver.exe。对这件事有什么想法吗?
发布于 2016-09-13 20:10:01
首先,您应该使用webdriver.ChromeOptions()方法来获得所需的结果,而不是使用Options()方法,其次,您应该指定安装在计算机上的Chromedrier的路径。
例如,将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")https://stackoverflow.com/questions/39478170
复制相似问题