【发布时间】:2015-04-03 03:41:40
【问题描述】:
我在笔记本电脑上运行 OS X 10.9.4,使用 Chrome 40.0.2214.94 和 Selenium 2.44.0,我使用 easy_install 为 Python 2.7 安装了它们。我的代码是 selenium 演练中的基本代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
但是当我运行它时,我得到了一个异常:
Traceback (most recent call last):
File "/Users/masongardner/Desktop/Selenium_tester.py", line 17, in <module>
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 59, in __init__
self.service.start()
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 66, in start
"ChromeDriver executable needs to be available in the path. "
selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
正如文档指定的那样,chrome 位于我机器上的这个位置:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
我可以做些什么来解决这个问题并开始按照我的计划从某些页面检索数据?如果您可以非常明确地了解代码更改或位置更改,因为我不是最精通计算的!
谢谢大家,希望我的问题不要太简单!
【问题讨论】:
标签: python-2.7 selenium selenium-chromedriver