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