gpt4 book ai didi

ruby - 将窗口的焦点更改为 capybara

转载 作者:行者123 更新时间:2023-12-05 06:20:50 24 4
gpt4 key购买 nike

编写一些测试时,我必须单击一个指向另一个选项卡的链接,然后我需要单击另一个链接,最后一步不起作用(无法找到链接“Example”(Capybara::ElementNotFound))。我是否需要先将焦点转移到新标签页?我该怎么做?

最佳答案

Tabs 在 Capybara 中被视为新窗口,因此您需要使用 Capybaras 窗口 api 移动到新窗口。它看起来像

new_window = window_opened_by do
# here you are in the context of the original window but your actions are expected to open a new tab/window
click_link 'the link that opens the new tab'
end

within_window(new_window) do
# this is in the context of the newly opened tab/window
click_link 'the link inside the new tab'
end

# here you will be back in the context of the first window

new_window.close # if you want to close the tab that was opened

关于ruby - 将窗口的焦点更改为 capybara ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60198829/

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