Getting Started
Load the Selenium Webdriver library
require 'selenium-webdriver'
Open a browser (Ex: Internet Explorer)
driver = Selenium::WebDriver.for :ie
Go to a specified URL
driver.navigate.to 'http://www.orbitz.com/'
driver.get 'http://www.orbitz.com/'
Close the browser
driver.close
Access an Element
Type somethign in the Text box or text area
driver.find_element(:id,'airOrigin').send_keys("MAA")
To Clear the text from text field
driver.find_element(:id,'airOrigin').send_keys [:control, 'a'], :space
Button
driver.find_element(:id,'BUTTON_ID'').click
Drop down list
select_box=driver.find_element(:id,'airStartTime')
options=select_box.find_elements(:tag_name=>"option")
options.each do |option_field|
if option_field.text == '12a-9a'
option_field.click
break
end
end
Check box
driver.find_element(:id,'airNonStopsPreferred').click
Radio button
driver.find_element(:id,'htlChoice').click
To verify Flights radio button selected or not
driver.find_element(:id,'airChoice').selected?
#if it returns TRUE then radio button already selected.
Return the title of the document
puts driver.title
Return true if the specified text appears on the TAG
puts driver.find_element(:class,'welcomeText').text.include?("Welcome to Orbitz")
To Click SPAN Elements
options=driver.find_elements(:tag_name=>"span")
options.each do |span_field|
if span_field.text == 'Find Flights'
span_field.click
break
end
end
thanks for the post.
One question… if I have a button on the page with no name or no id, jjust a text on the button, how can I click it?
Can you please send the HTML code button ?
this for example:
input type=”submit” id=”searchsubmit” value=”Search”
Please try this
driver.find_element(:id,’searchsubmit’).click
OR
driver.find_element(:value,’Search’).click
Not working in my case
Look at this code:
require “selenium-webdriver”
driver = Selenium::WebDriver.for :chrome
driver.navigate.to “http://www.quackit.com/javascript/javascript_alert_box.cfm”
sleep 2
driver.find_element(:value=> “Click me…”).click
sleep 2
@Mario: Check out – http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/FindBy.html