Testing if a new window opens with Watir-Webdriver
Asked Answered
V

2

7

I'm using Watir-webdriver and I was wondering if there was a good way to check if a new window opens. I've googled around a bit and couldn't find anything though it feels like there should be an easy answer.

I have a printer friendly link and I want to test that the link opens in a new window or tab and I would like to test this with ie, firefox, chrome and safari if possible.

Thanks!

Volplane answered 11/7, 2011 at 15:42 Comment(0)
B
12

You can check the number of windows:

browser.windows.size

or check if a specific window exists:

browser.window(:title => "foo").exists?

More examples in the specs.

Barbaresi answered 11/7, 2011 at 18:49 Comment(0)
O
3

You can also use index based browser window checking where you need to worry about index only and it follows zero based index ordering. So, the default window is of index: 0 and if a new window opens it will be of index: 1, the next will be of index: 2 and so on.

To check first child window if you want to test that the link opens in a new window ,

browser.window(index: 1).exists?

Or to work inside this window,

browser.window(index: 1).use do
  # do scripting here
end
Outmoded answered 18/9, 2017 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.