Reputation: 7940
I found a code: page.driver.browser.switch_to.window
, which is apparently switching to already opened window. How do we open a new window using page.driver.browser object?
Thanks
Upvotes: 3
Views: 5168
Reputation: 346
I ended up here, even if is a old thread, might be useful for someone, you can create and use windows like this:
new_window = open_new_window
switch_to_window new_window
or:
within_window new_window do
end
you can also find new windows through windows object.
open_new_window
new_window = windows.last
References:
http://www.rubydoc.info/github/jnicklas/capybara/Capybara/Session:open_new_window
http://www.rubydoc.info/github/jnicklas/capybara/Capybara%2FSession%3Aswitch_to_window
https://github.com/teamcapybara/capybara#working-with-windows
With Capybara, how do I switch to the new window for links with "_blank" targets?
Upvotes: 9
Reputation: 7940
I ended up using JavaScript to do this:
When /^I open a new window for "([^"]*)"$/ do |url|
str =
<<END_TAG
window.open("#{url}", "window_name", "height=800,width=1000");
END_TAG
page.execute_script(str)
end
Upvotes: 2