在水豚/Poltergeist中打开新标签页 [英] Opening a new tab in Capybara / Poltergeist

查看:84
本文介绍了在水豚/Poltergeist中打开新标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用水豚/poltergeist单击链接来打开链接,该链接会在新标签页中打开.

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(<link>).click

似乎和

click_link "<link>"

@session.driver.window_handles 

无论我在做什么,似乎都只能给我1个窗口.

Only seems to give me 1 window whatever I'm doing.

我如何在新标签页中打开该链接?

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

对于什么起作用或不起作用似乎有些困惑().

Seems to be a fair amount of confusion as to what works or doesn't a la (With Capybara, how do I switch to the new window for links with "_blank" targets?).

希望有人解决了这个问题...似乎无法阻止我解决这个问题.

Hoping somebody has worked it out... Can't seem to get my head around it.

好的.通过更新到最新版本的poltergeist(1.6.0),我们取得了一些进展.

Ok. By updating to the latest version of poltergeist (1.6.0) we have some progress.

现在,我有两个窗口,但不知道如何在两个窗口之间切换.

Now however I have two windows but no idea how to switch between them.

@session.windows

给我

[Window @ handle ="0",Window @ handle ="1"] (由于有点有趣而稍作修改).

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

但是

@session.switch_to_window(1)

结果

NoMethodError: undefined method `handle' for "1":String

推荐答案

正确的是,截至2014年2月5日,以及poltergeist v1.6版,您可以按照...

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...

这篇关于在水豚/Poltergeist中打开新标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆