Opening a new tab in Capybara / Poltergeist

I am trying to open a link by clicking on it using capybara / poltergeist, which opens in a new tab.

I can not make it work.

@session.find(<link>).click 

just seems to remain on the same page as

 click_link "<link>" @session.driver.window_handles 

It seems to me that I have 1 window, no matter what I do.

How do I get this link to open in a new tab?

There seems to be quite a bit of confusion as to what works or doesn't work ( With Capybara, how do I go to a new window for links with "_blank"? Goals? ).

Hoping that someone handled this ... It seems I can’t think about it.

Ok When upgrading to the latest poltergeist (1.6.0), we have some progress.

Now, however, I have two windows, but I don’t know how to switch between them.

 @session.windows 

gives me

[Window @handle = "0", Window @handle = "1"] (slightly modified as it was a bit funny).

But

 @session.switch_to_window(1) 

leads to

 NoMethodError: undefined method `handle' for "1":String 
+6
source share
2 answers

On the right, from February 5, 2014 and v1.6 poltergeist you can do it like ...

 @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 this clears for someone ...

+6
source

I did it with

 page.switch_to_window(page.windows[0]) 

Maybe this is useful to someone.

+2
source

Source: https://habr.com/ru/post/982227/


All Articles