2016-08-04 74 views
0

我想讓Selenium工作,但我似乎無法弄清楚。我已經安裝了適當的Ruby gem,並試圖執行此代碼。Selenium和ChromeDriver故障

require "selenium-webdriver" 

driver = Selenium::WebDriver.for :chrome 
driver.navigate.to "http://google.com" 

element = driver.find_element(:name, 'q') 
element.send_keys "Hello WebDriver!" 
element.submit 

puts driver.title 

driver.quit 

我很確定我的問題是我沒有正確連接ChromeDriver。如何鏈接Chrome驅動程序才能使其正常工作?它說我需要把它放在我的PATH上。有人可以解釋這個嗎?

Here is what I downloaded.

而且,這裏是我得到的錯誤:

in `executable_path': Unable to find the chromedriver executable. 

回答

2

有一個Selenium::WebDriver::Chrome.driver_path=方法,允許chromedriver可執行的指定:

# Specify the driver path 
Selenium::WebDriver::Chrome.driver_path = "path/to/chromedriver.exe" 

# now instantiate chrome driver 
driver = Selenium::WebDriver.for :chrome 
driver.navigate.to "http://google.com" 

element = driver.find_element(:name, 'q') 
element.send_keys "Hello WebDriver!" 
element.submit 

puts driver.title 

driver.quit 
0

廣場鉻司機取決於您的操作系統,請檢查this link

OS Expected Location of Chrome 
Linux /usr/bin/google-chrome1 
Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome 
Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe 
Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe 
0

無法找到chromedriver可執行文件: 我們得到這個當系統無法找到chromedriver。我們可以通過設置環境變量「webdriver.chrome.driver」幫助系統找到它。 如果您正在運行unix/linux,使用 export webdriver.chrome.driver=<path_where_binary_is_present> 如果在窗口上運行: 轉到系統高級環境變量。添加名爲webdriver.chrome.driver的條目並將值設置爲二進制路徑

我們也可以從程序中設置此位置。像Java中 System.setProperty(「webdriver.chrome.driver」,「」

做的這個任意一個,但此錯誤應該消失