gpt4 book ai didi

webdriver - watir 网络驱动程序 : how to switch to another window open with target

转载 作者:行者123 更新时间:2023-12-04 16:22:19 26 4
gpt4 key购买 nike

我正在使用 watir-webdriver,当点击带有 target="_blank"的链接时,它会打开一个我无法控制的新窗口,但仍然需要验证是否打开了 404 页面以外的内容,以及是否打开了那个新窗口包含一些关键字。我不知道那个窗口的标题是什么(它不是一直都一样),所以 this solution没有帮助。

是否有任何已知的方法可以通过 watir-webdriver 处理这些 target="_blank"窗口?

最佳答案

由于您知道新窗口的标题应该具有某些形式,因此您应该能够使用正则表达式(用“/”表示的正则表达式)通过其标题来定位它。

browser.window(:title => /known part of title/).use do
#Whatever you want to do with the popup
end

或者,如果您真的对弹出窗口一无所知,您可以创建最后一个窗口:
browser.windows.last.use do
#Whatever you want to do with the popup
end

关于webdriver - watir 网络驱动程序 : how to switch to another window open with target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15233183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com