9

In Capybara, is it possible to open a link in a new window, rather than the current one?

EyalB
  • 423
  • 3
  • 9
  • 1
    Yes, you can use javascript to do that with window.open. See e.g. http://stackoverflow.com/questions/13056763/how-do-i-open-a-new-window-in-capybara-with-selenium-webdriver – Bjoern Rennhak May 12 '13 at 02:12
  • Should it be a new window or a new tab? For the second variant see http://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver – olyv Apr 12 '14 at 15:49

1 Answers1

6

If this element is a link you can just get its href and open it in a new window:

url = find('.some_link')[:href]
within_window open_new_window do
  # do something
end

open_new_window has been added in Capybara 2.3

Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123