簡體   English   中英

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

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

我之前在Java和OpenSUSE中使用了Selenium 2。 現在,在Mac上,並希望將其設置為與Python 2.7一起使用。 我已經下載並解壓縮了硒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即將問世。 這就是echo $ PATH給我的:

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

可能缺少什么?

看起來您將可執行文件本身放在PATH中,而不是包含它的目錄中。

在您的PATH中嘗試/Users/rohitdholakia/Downloads

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM