---
title: "Is there an alternative to watir::ie.attach for watir-webdriver since attach is "
author: "lilingjay"
date: "2012-03-31T23:27:41Z"
tags: []
categories: ["开源软件"]
slug: "is-there-an-alternative-to-watir-ie-attach-for-watir-webdriver-since-attach-is"
draft: false
lastmod: "2012-03-31T23:33:56Z"
id: 1472013
url: "https://lilingjay.iteye.com/blog/1472013"
---

原文链接 [http://stackoverflow.com/questions/5796059/is-there-an-alternative-to-watirie-attach-for-watir-webdriver-since-attach-is](http://stackoverflow.com/questions/5796059/is-there-an-alternative-to-watirie-attach-for-watir-webdriver-since-attach-is)

Question:

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
```

```

```

```
Answers:
```

```
A1:"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](http://groups.google.com/group/watir-general/browse_thread/thread/232df221602d4cfb)

 

A2: 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