How to set WATIR orientation to a new window

I am new to WATIR testing (and I like it!) And ran into the problem of reorienting my WATIR script to a newly opened window. Here is my (simplified) script ....

#!/usr/bin/ruby
require 'rubygems'
require 'watir-webdriver'
browser=Watir::Browser.new
browser.goto("http://0:3050")

browser.text_field(:name,"userkey300203830").set("OKJHNB")
browser.button(:id, "interview48").click

puts "Expected Result:"
puts "A successful display of cars"

if browser.window(:title=>"300203830").exists?
   puts " Test passed. New window opened!"
else
   puts " Test Failed! No window found"
end

Everything works to the very end. After pressing the "interview48" key, a new window opens with the heading "300203830". Looks like I'm finding this, but I just don't know how to focus on this window now.

+5
source share
3 answers
browser.window(:title => "300203830").use do
  # do something
end

Additional information: http://watir.imtqy.com/docs/browser-popups/

+7
source
browser.windows.last.use 
browser.windows.first.use

, .

+6

Additionally, for more than two windows, you can use the following:

browser.windows[n].use  

#n is a variable for the window. n will access them in opening order or tabs from left to right

+6
source

All Articles