I'm using watir-webdriver, and when clicking on a link with target="_blank" it opens a new window, which I have no control of, but still need to verify that something other than 404 page opened, and if title of that new window contains some keywords. I don't know upfront what title of that window will be (it's not the same all the time), so this solution doesn't help.
Are there any known ways how to handle those target="_blank" windows through watir-webdriver?
Since you know that the title of the new window should have certain forms, you should be able to locate it via its title using a regex (regular expression denoted with the "/").
browser.window(:title => /known part of title/).use do
#Whatever you want to do with the popup
end
Alternatively, if you really do not know anything about the popup, you can get the last window created:
browser.windows.last.use do
#Whatever you want to do with the popup
end
There's a link to the watir-webdriver window switching spec on http://watirwebdriver.com/browser-popups/. You should be able to find the window by :title
, :url
, or :index
. Examples from the spec:
browser.window(:index => 1).use
browser.window(:url => /closeable\.html/).use
browser.window(:title => "closeable window").use
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With