6

I have a link that opens in a new window, and I need to test the part of my app that is within that new window.

Any suggestions will be much appreciated.

3 Answers 3

15

Define a step that contains this code:

page.driver.browser.switch_to.window (page.driver.browser.window_handles.last)

switch_to is a selenium command that allows you to change over to a new window window_handles returns a list of currently open windows

0
1

I realize this is a very old post, but here's a Cucumber step definition using Capybara and the Poltergeist driver:

And /^I follow "([^"]*)" to the new window$/ do |link|
  new_window = window_opened_by { click_link link }
  switch_to_window new_window
end
0

Could you just validate that the link has it's target set to _blank?

2
  • no, cause I need to run tests on the stuff that the link points too... actually... I think I can pull that information with x_path.. thanks for helping think! Jul 20, 2010 at 21:27
  • Ah, you should just be able to say "Then I follow the link 'login'"
    – jspooner
    Jul 20, 2010 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.