使用ChromeDriver在Mac OS X上设置Selenium 2

时间:2013-01-16 01:28:07

标签: python macos selenium-webdriver

之前我使用过Selenium 2和java和OpenSUSE。现在,我在Mac上,并希望将其设置为与Python 2.7一起使用。我已经下载并解压缩了selenium 2.28并下载了ChromeDriver并将其保存在/ Users / username / Downloads中。并更新bash_profile中的路径。但是,当我运行一个简单的代码片段时,就像这样,

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("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()

我刚把它从文档中拿出来进行测试。我收到如下错误:

Traceback (most recent call last):
  File "python_selenium_testing.py", line 4, in <module>
    driver = webdriver.Chrome()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium-2.27.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 61, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium-2.27.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 64, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://code.google.com/p/selenium/downloads/list                and read up at http://code.google.com/p/selenium/wiki/ChromeDriver'

但是,chromedriver正在走上正轨。这就是回声$ PATH给我的:

Other stuff:***/Users/rohitdholakia/Downloads/chromedriver***

可能缺少什么?

1 个答案:

答案 0 :(得分:0)

看起来您将可执行文件本身放在PATH中而不是包含它的目录中。

在路径中尝试/Users/rohitdholakia/Downloads