Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on webdriver

I have a website which is only rendered in Webkit enabled browser (Google Chrome, Safari). I am using Google Chrome since I am on Windows 7.

I am using Watir-WebDriver to automate the same.

Issue: When I click on a button on the browser window, is launches another window and post click content is rendered in the new browser window. I need a way to be able to Identify this new browser window, in-order to be able to proceed with my testing. I have been reading on various forums, but not getting any certain answer/solution.

Q: Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on Watir-Webdriver

Sample code:

require "rubygems"

require "watir-webdriver"


require "selenium-webdriver"

b = Watir::Browser.new(:chrome)

website = "http://xyz.com"

#a new browser is launched and the website is opened

b.goto(website)

#this opens a new browser window

b.link(:xpath,"/html/body/div/ul/li/a").click

#there is a button called "MAP" on the new browser window

b.link(:id,"btn_MAP")

#this gives an error, unknown link
like image 454
Raat Avatar asked Apr 26 '11 20:04

Raat


2 Answers

"window" method is the alternative for ie.attach. Webdriver can handle the window opened by itself with window method.

b.link(:href,/server\/getPage/).click
b.window(:url,/server\/getPage/i).use do
  b.link(:id,"btn_MAP").click
end

you can handle popped up windows in the window method block. If you want to keep handling popped up window, use it without block, like window(:url,/foobar/).use

see also: http://groups.google.com/group/watir-general/browse_thread/thread/232df221602d4cfb

like image 66
Yutaka Yamaguchi Avatar answered Oct 01 '22 02:10

Yutaka Yamaguchi


@Yutaka: Thanks a lot for all your help it lead me to use something like the following and it worked!

b.link(:xpath,"/html/body/div/ul/li/a").click

c = b.window(:url,"http:\/\/server\/getPage\/67\/1354")

c.use

b.link(:id,"btn_MAP").click

like image 33
Raat Avatar answered Oct 01 '22 02:10

Raat