Watir webdriver: how to switch to another window with the target

I use watir-webdriver, and when I click on the link with target = "_ blank" a new window opens, which I do not control, but still need to check that something other than 404 pages has opened, and if the title of this new window contains several keywords. I do not know what title of this window will be (this is not the same thing), so this solution does not help.

Are there any known ways to handle these target = "_ blank" windows through watir-webdriver?

+4
source share
2 answers

Since you know that the title of the new window must have certain forms, you should be able to find it through your title with the help of a regular expression (regular expression denoted as "/").

browser.window(:title => /known part of title/).use do #Whatever you want to do with the popup end 

Alternatively, if you really don't know anything about the popup, you can create the last window:

 browser.windows.last.use do #Whatever you want to do with the popup end 
+13
source

The link http://watirwebdriver.com/browser-popups/ has a link to the browser switching specification watir-webdriver. You can find the window :title :url or :index . Examples from the specification:

 browser.window(:index => 1).use browser.window(:url => /closeable\.html/).use browser.window(:title => "closeable window").use 
+6
source

All Articles