2010-05-08 90 views
4

令人驚訝的是,我找不到關於如何設置Selenium WebDriver通過谷歌大學使用selenium-webdriver gem的第一步指南。我想這個寶石需要知道我在哪裏存儲所有這些jar文件來開始。我該如何配置?如何設置Selenium WebDriver使用selenium-webdriver gem

+0

沒關係,事實證明我不需要做任何事情! – yiwen 2010-05-09 05:56:07

回答

10

首先,你必須安裝寶石硒的webdriver:

創業板安裝硒的webdriver

然後你就可以開始你的Ruby程序:

#You need to require the gem "selenium-driver" 
require "selenium-webdriver" 

#... see webdriver ruby api docs here: http://selenium.googlecode.com/svn/trunk/docs/api/rb/_index.html 
#... Most usefull classes are Driver and Element, check them out for a good start 
driver = Selenium::WebDriver.for :firefox 
driver.navigate.to "http://www.google.com" 
element = driver.find_element(:name, 'q') 
element.send_keys "Hello WebDriver!" 
element.submit 
puts driver.title 
driver.quit 

你可以找到更多信息:

about webdriver and ruby (all said above was an attempt to summarize it)

about the Ruby webdriver API

正如你所看到的一樣,Webdriver API本身具有不同的「樣式」的普通硒-ruby程序......如果你想使用webdriver並仍然繼續用Selenium-API編程,您應該切開Selenium2.0遠程服務器,因爲它似乎將以透明的方式使用Webdriver,同時仍然維持着相同的已知Selenium紅寶石API

如果我對部分信息有誤,請糾正我,我們將一起使其更清晰:)

PD:最好找到關於Selenium和Webdriver之間的關係的信息是this博客文章

相關問題