What actually happens below? See my comments after #
Would really appreciate if someone wanted to take the time to explain.
require 'rubygems' #lib?
You don't need this in Ruby 1.9
require 'selenium-webdriver' #lib?
Have a look at this:
http://watirmelon.com/2011/05/05/selenium-webdriver-vs-watir-webdriver-in-ruby/
driver = Selenium::WebDriver.for :firefox #instantiate driver with
Selenium and Webdriver methods?
This just creates an instance of firefox with a temp profile which can
be controlled via Selenium-webdriver
driver.get "http://google.com"
element = driver.find_element :name => "q" # What happens here? :name =>
"q"?
The element on the page with the name "q" happens to be the search text
field. I recommend using Firebug to find out what each element can be
identified by.
element.send_keys "Cheese!"
element.submit
puts "Page title is #{driver.title}"
wait = Selenium::WebDriver::Wait.new(:timeout => 2)#Wait is a new class?
Watir-webdriver's latest version has waiting built-in, it looks like
Selenium has a seperate wait module.
wait.until { driver.title.downcase.start_with? "cheese!" }#Verify that
cheese has been printed?
You're passing a block to the wait module, until method which will stop
waiting once it evaluates to "true". This waits until the page has
loaded to a point that it has changed the title of the browser window.
puts "Page title is #{driver.title}"
driver.quit
I'm not sure about Selenium, but with watir-webdriver using "close"
rather than "quit" cleans up the temp files as well.
Best Regards
Mattias
This is what the same sequence looks like with watir-webdriver:
require 'watir-webdriver'
driver = Watir::Browser.new :firefox
driver.goto "http://google.com"
element = driver.text_field(:name => "q")
element.set "Cheese!\n"
puts "Page title is #{driver.title}"
driver.wait_until { driver.title.downcase.start_with? "cheese!" }
puts "Page title is #{driver.title}"
driver.close
···
--
Posted via http://www.ruby-forum.com/\.