Watir WebDriver — Handling New Window
December 1, 2011
Situation:
1. You are in Parent Page.
2. Clicking link “Open” in Parent page.
3. It opens new window
4. You need to do actions there and come back to your parent window
Solution:
To Click the Link
require 'rubygems'
require 'watir-webdriver'
ff=Watir::Browser.new :ff
ff.goto("website.com")
ff.link(:text,'open').click
To handle the New window and performing some actions within that window,
ff.window(:title,/TITLE of the new window/i).use do
ff.send_keys('SampleText')
ff.button(:id,'insert').click
puts ff.title #returns the new window title
end
within a loop The button belongs to Newly opened window.
puts ff.title #returns the parent window title
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