Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a new window in Capybara with Selenium webdriver?

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

like image 317
user_1357 Avatar asked Oct 26 '25 22:10

user_1357


1 Answers

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?

like image 93
Juliano Avatar answered Oct 28 '25 15:10

Juliano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!