使用 Capybara,如何切换到带有“_blank"的链接的新窗口?目标? [英] With Capybara, how do I switch to the new window for links with "_blank" targets?

查看:25
本文介绍了使用 Capybara,如何切换到带有“_blank"的链接的新窗口?目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这实际上并不是我遇到的问题,但似乎当我click_link"一个带有 target="_blank" 的链接时,会话将焦点保持在当前窗口上.

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

所以我要么希望能够切换到新窗口,要么忽略 _blank 属性 - 本质上,我只是希望它实际转到链接指示的页面,以便我可以确保它是正确的页面.

So I either want to be able to switch to the new window, or to ignore the _blank attribute - essentially, I just want it to actually go to the page indicated by the link so I can make sure it's the right page.

我使用 webkit 和 selenium 驱动程序.

I use the webkit and selenium drivers.

我在下面提交了迄今为止的发现.非常感谢提供更详尽的答案.

I submitted my findings thus far below. A more thorough answer is much appreciated.

此外,这仅适用于 selenium - 非常感谢 webkit 驱动程序的等效项(或指出我可以在哪里发现它).

Also, this only works with selenium - the equivalent for the webkit driver (or pointing out where I could discover it myself) would be much appreciated.

推荐答案

Capybara >= 2.3 包括新的窗口管理 API.它可以像这样使用:

Capybara >= 2.3 includes the new window management API. It can be used like:

new_window = window_opened_by { click_link 'Something' }
within_window new_window do
  # code
end

这篇关于使用 Capybara,如何切换到带有“_blank"的链接的新窗口?目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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