Reputation: 39763
There are a lot of questions on stackoverflow already addressing how to handle a new Watir window once its already there, i.e. from a popup in most examples.
The answers to those questions talk about the browser.windows[n].use
command, and so on.
But I'm trying to intentionally generate a second window that can be added to the stack of windows in the windows command.
I've tried this so far...
b = Watir::Browser.new
bb = Watir::Browser.new
b.windows << bb.window
...but the changes didn't persist.
b.windows.count
#=> 1
Is there any way I can generate a second browser window without creating a new Watir::Browser object? (I already know Watir for Firefox doesn't support tabs)
Upvotes: 1
Views: 86
Reputation: 46846
One solution I have seen in the past, was to use javascript to open a new window:
# Open the first browser window as normal
b = Watir::Browser.new
b.windows.count
#=> 1
# Execute javascript to open a second window
b.execute_script('window.open();')
b.windows.count
#=> 2
Note that there is a single Watir browser object, but it knows of 2 windows.
Upvotes: 3