简体   繁体   English

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

[英]Setting up Selenium 2 on Mac OS X with ChromeDriver

I have used Selenium 2 before with java and OpenSUSE. 我之前在Java和OpenSUSE中使用了Selenium 2。 Now, am on a Mac and want to set it up for use with Python 2.7 . 现在,在Mac上,并希望将其设置为与Python 2.7一起使用。 I have downloaded and unzipped the selenium 2.28 and downloaded ChromeDriver and kept it in in /Users/username/Downloads. 我已经下载并解压缩了硒2.28,并下载了ChromeDriver,并将其保存在/ Users / username / Downloads中。 And update the path in bash_profile. 并更新bash_profile中的路径。 But, when I run a simple code snippet, like this , 但是,当我运行这样的简单代码段时,

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()

I just took it from the documentation to test. 我只是从文档中进行测试。 I get an error like the following : 我收到如下错误:

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'

But, chromedriver is on the path. 但是,chromedriver即将问世。 This is what echo $PATH gives me : 这就是echo $ PATH给我的:

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

What could be missing? 可能缺少什么?

It looks like you put the executable itself in the PATH instead of the directory containing it. 看起来您将可执行文件本身放在PATH中,而不是包含它的目录中。

Try /Users/rohitdholakia/Downloads in your PATH. 在您的PATH中尝试/Users/rohitdholakia/Downloads

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM