With Capybara, how do I switch to the new window for links with “_blank” targets?

后端 未结 15 2011
花落未央
花落未央 2020-12-02 09:54

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 w

15条回答
  •  再見小時候
    2020-12-02 10:02

    Capybara provides some methods to ease finding and switching windows:

    facebook_window = window_opened_by do
      click_button 'Like'
    end
    within_window facebook_window do
      find('#login_email').set('a@example.com')
      find('#login_password').set('qwerty')
      click_button 'Submit'
    end
    

    More details here: Capybara documentation

提交回复
热议问题