Perhaps this isn't actually the issue I'm experiencing, but it seems that when I "click_link" a link with target="_blank", the session keeps the focus on the current window.
So I either want to be able to switch to the new window, or to ignore the _blank attribute - essentially, I just want it to actually go to the page indicated by the link so I can make sure it's the right page.
I use the webkit and selenium drivers.
I submitted my findings thus far below. A more thorough answer is much appreciated.
Also, this only works with selenium - the equivalent for the webkit driver (or pointing out where I could discover it myself) would be much appreciated.
I had this issue when opening links in an gmail window: I fixed it like this:
This is now working with Poltergeist. Although
window_handles
is still not implemented (you need a window name, i.e. via a JavaScript popup):Edit: Per comment below, Poltergeist now implements
window_handles
since version 1.4.0.Seems like it is not possible with capybara-webkit right now: https://github.com/thoughtbot/capybara-webkit/issues/271
:-(
At the same time https://github.com/thoughtbot/capybara-webkit/issues/129 claims it is possible to switch windows with
within_window
.Also https://github.com/thoughtbot/capybara-webkit/issues/47 suggests that
page.driver.browser.switch_to().window(page.driver.browser.window_handles.last)
works. Ah well, on to code reading.The code at https://github.com/thoughtbot/capybara-webkit/blob/master/lib/capybara/webkit/browser.rb at least has some references that suggest that the API that works for webdriver / firefox is also working for webkit.
Now within_window implemented for capybara-webkit http://github.com/thoughtbot/capybara-webkit/pull/314 and here you can see how to use it http://github.com/mhoran/capybara-webkit-demo
You can pass a name, url or title of the window also (But now its dipricated)
You can pass a labda or a proc also
wish it stretches the method usage to more clearly understaing
Capybara >= 2.3 includes the new window management API. It can be used like: