Automating ‘Auto Complete’ text field using Watir-WebDriver
February 9, 2012
Requirement:
1. Navigate to Google.com
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
Convert Webpage into PDF files using Ruby gems — Watir-Webdriver + Prawn
December 10, 2011
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("http://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.
Watir-webdriver cheatsheet
October 6, 2011
Getting Started Load the Watir Webdriver libraryrequire 'watir-webdriver'Open a browser (Ex: Internet Explorer)driver = Watir::Browser.new :ieGo to a specified URLdriver.goto 'http://www.orbitz.com/'Close the browserdriver.closeAccess an Element Type something in the Text box or text areadriver.text_field(:id,'airOrigin').set("MAA")To Clear the text from text fielddriver.text_field(:id,'airOrigin').clearButton To click the buttondriver.button(:id,'BUTTON_ID'').clickDrop down list To select the value from listdriver.select_list(:id,'airStartTime').select("1 am")To get the selected value from select fielddriver.select_list(:id,'airStartTime').valueCheck box To clik the check boxdriver.checkbox(:id,'airNonStopsPreferred').clickORdriver.checkbox(:id,'airNonStopsPreferred').setTo know the clicked? or not ?driver.checkbox(:id,'airNonStopsPreferred').set?Radio buttondriver.radio(:id,'htlChoice').clickTo verify Flights radio button selected or notdriver.radio(:id,'htlChoice').set?#if it returns TRUE then radio button already selected. To get the title of the webpageputs driver.titleReturn true if the specified text appears on the TAGputs driver.li(:class,'welcomeText').text.include("Welcome to Orbitz")To Click SPAN Elementsdriver.span(:text,'Find Flights').click