Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set WATIR focus on new window

I'm new to WATIR testing (and do I love it!) and have run into a wall on how to refocus my WATIR script to a newly opened window.. Here's 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

It all works right up to the end. After the key "interview48" is clicked, a new window is opened with the title "300203830". Looks like I find it but I just don't know how to now focus on that window.

like image 964
Jane Wilkie Avatar asked May 22 '12 19:05

Jane Wilkie


1 Answers

browser.window(:title => "300203830").use do
  # do something
end

More information: http://watir.github.io/docs/browser-popups/

like image 153
Željko Filipin Avatar answered Sep 28 '22 05:09

Željko Filipin