Reputation: 1334
Hello !
I am currently using Selenium with Python on Windows 7, and I tried to use the Chrome webdriver for the hide function --no-startup-window
. After I installed Chrome (x86), copied chromedriver.exe on path C:\Python27\Scripts\
and added it on PATH environment, I tried to launch it via the following code:
opt = Options()
opt.add_argument("--no-startup-window")
driver = webdriver.Chrome(chrome_options=opt)
However, I have the following error when I execute it:
(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
Note: I am currently using a virtualenv
also, so I also copied the chromedriver.exe on his Scripts
folder. Any idea about the issue here ?
Upvotes: 0
Views: 3394
Reputation: 4442
first , instead of using Options() method you should use webdriver.ChromeOptions() method to have the result that you want, secondly you should specify the path to the Chromedriver installed on your computer.
for example put chormedriver.exe file on drive C:\ and use:
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")
Upvotes: 2