Please how do get selenium working in this scenerio? I have seen this questions times with fewer or no answers and i hope luck is on my side today.
Let me start by detailing my environment.
I am using virtualenv/virtualenvwrapper with python3 to run the following.
from selenium import webdriver from selenium.webdriver.common.keys import Keys import os chromedriver = "/usr/local/bin/chromedriver" os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome() driver.get("http://www.python.org") print(driver.title) driver.quit()
The lines below were added after i followed example from similar question here
chromedriver = "/usr/local/bin/chromedriver" # i used brew to install chrome to get this path from the command 'which chromedriver'
os.environ["webdriver.chrome.driver"] = chromedriver
Alternatively i downloaded chromedriver directly from github and added the path as follows:
/Users/Me/Downloads/chromedriver
I have triend not passing arguements to the driver but i still get this error.
Traceback (most recent call last):
File "aicpa.py", line 8, in <module>
driver = webdriver.Chrome()
File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 102, 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
Complements of the season and thanks in advance.
你试过这个吗?
webdriver.Chrome("/usr/local/bin/chromedriver")
I didn't test this but please try:
chromedriver = "/usr/local/bin"
os.environ[] simply adds a path variable which has to be a folder and NOT a file.
在我的情况下,将127.0.0.1 localhost
添加到hosts
文件解决了这个问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.