【问题标题】:Setting up Selenium 2 on Mac OS X with ChromeDriver使用 ChromeDriver 在 Mac OS X 上设置 Selenium 2
【发布时间】:2013-01-16 01:28:06
【问题描述】:

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

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 正在路上。这就是 echo $PATH 给我的:

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

可能缺少什么?

【问题讨论】:

    标签: python macos selenium-webdriver


    【解决方案1】:

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

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

    【讨论】:

    • 在添加 Q 之后,我遇到了另一个 stackoverflow Q,显然 python 绑定有一些错误(现在可能已经解决,不知道)。无论如何使用“brew install”安装了chromedriver,现在它可以工作了!谢谢
    猜你喜欢
    • 2013-07-27
    • 2014-05-06
    • 1970-01-01
    • 2012-01-03
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    相关资源
    最近更新 更多