Opening a new tab in Capybara / Poltergeist

前端 未结 3 1325
醉话见心
醉话见心 2021-01-12 20:35

I\'m trying to open a link by clicking on it using capybara/poltergeist which opens up in a new tab.

I can\'t seem to get it working.

@session.find         


        
相关标签:
3条回答
  • 2021-01-12 20:46

    This is what worked for me using Capybara 3.33:

    new_window = window_opened_by do
      click_link 'Go to external page'
    end
    
    within_window new_window do
      assert_current_path 'http://external-page.com/?q=lala'
    end 
    
    0 讨论(0)
  • 2021-01-12 20:53

    Right, as of Feb 5th 2014 and v1.6 of poltergeist, you can do this, as ...

    @session.click_on "link_with_target _blank"
    
    @session.switch_to_window(@session.windows.last)
    #Do whatever you're doing
    @session.current_window.close
    @session.switch_to_window(@session.windows.first)
    

    Hope that clears things up for somebody...

    0 讨论(0)
  • 2021-01-12 21:00

    I did this with

    page.switch_to_window(page.windows[0])
    

    Maybe that's useful to someone.

    0 讨论(0)
提交回复
热议问题