Auto Complete · Ruby · watir-webdriver

Automating ‘Auto Complete’ text field using Watir-WebDriver

Requirement:

1. Navigate to Google.com

2. Type “Ravee” in text Field
 3. Select “Raveendran” from Auto Complete option from Suggested option.
Steps to Solve the issues:
1. Navigate to Google.com
2. Type “Rav” in text Field
3. Using IE Developer Tool Bar –> Click The suggested Option (So You will get the source code for suggestion lists)
4. Find the parent id –> Ex. It should TABLE mostly.
So we have Table id/name/class
5. Collect All the Rows under this table
6. Check the text for each and every row
7. If Any one of the row matches  “Raveendran”
8. Then Simply Click It
Code:

require 'rubygems'
require 'watir-webdriver'

browser=Watir::Browser.new :ie
browser.goto("google.com")

browser.text_field(:name,"q").set("Ravee")
sleep 3
auto_content=browser.table(:class,'gssb_m').trs

auto_content.each do |g|
  if g.text.downcase == "raveendran"
    g.click
    sleep 3
    break
  end
end

 

Demo –> http://bit.ly/j_autocomplete_watir

Jazzez · pdf-reader · Prawn · Ruby · Ruby 1.9 · ruby excercise · watir

Convert Webpage into PDF files using Ruby gems — Watir-Webdriver + Prawn

Installation : 

1. Install Ruby 1.8.7 or 1.9.2

2. Install WatirWebdriver — Refer  http://rubygems.org/gems/watir-webdriver

a. CMD>gem install watir-webdriver

3. Install Prawn Library

a. CMD>gem install prawn

Sample Code:

require 'rubygems'
require 'watir-webdriver'
require 'prawn'

ff=Watir::Browser.new :ff

ff.goto("https://raveendran.wordpress.com")

Prawn::Document.generate('c:\\test123\\hello.pdf') do |pdf|
pdf.text(ff.text)
end

ff.close

Output:

hello PDF  file contains all the TEXT from Webpage

 

Open Issues:

Alignment issue occurs depends upon web page Design. But You wont miss to collect all the Text from Webpage.

cheat · cheat sheet · QA · Ruby 1.9 · ruby excercise · watir · watir-webdriver

Watir-webdriver cheatsheet

Getting Started

Load the Watir Webdriver library

require 'watir-webdriver'

Open a browser (Ex: Internet Explorer)

driver = Watir::Browser.new :ie

Go to a specified URL

driver.goto 'http://www.orbitz.com/'

Close the browser

driver.close

Access an Element

Type something in the Text box or text area

driver.text_field(:id,'airOrigin').set("MAA")

To Clear the text from text field 

driver.text_field(:id,'airOrigin').clear

Button

To click the button
driver.button(:id,'BUTTON_ID'').click

Drop down list

To select the value from list
driver.select_list(:id,'airStartTime').select("1 am")

To get the selected value from select field
 driver.select_list(:id,'airStartTime').value

Check box

To clik the check box

driver.checkbox(:id,'airNonStopsPreferred').click
OR
driver.checkbox(:id,'airNonStopsPreferred').set
To know the clicked? or not ?
driver.checkbox(:id,'airNonStopsPreferred').set?

Radio button driver.radio(:id,'htlChoice').click

To verify Flights radio button selected or not

driver.radio(:id,'htlChoice').set?

#if it returns TRUE then radio button already selected.

To get the title of the webpage puts driver.title

Return true if the specified text appears on the TAG

 puts driver.li(:class,'welcomeText').text.include("Welcome to Orbitz")

To Click SPAN Elements driver.span(:text,'Find Flights').click