Selenium WebDriver – Cheat Sheet

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

Advertisements

12 thoughts on “Selenium WebDriver – Cheat Sheet

  1. Mario Ruiz says:

    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?

  2. Gayathri says:

    Hi
    for drop down box list which you have given the code above doesnot work for me, i am getting undefinied method ‘each’ for selenium::webDriver::Element::

  3. There are also different kinds of pigs for different levels while their number increases as the player
    level increases. However, antivirus problems like Avast often conflict with Real – Arcade games due to the following error or virus detection:
    . As computer and video games have increased exponentially in popularity over time, they
    have caused significant impact upon popular culture.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s