改变窗口在水豚上的焦点

问题描述 投票:0回答:1

编写一些测试,我必须单击指向另一个选项卡的链接,然后我需要单击另一个链接,最后一步无法正常工作(无法找到链接“ Example”(示例)(Capybara :: ElementNotFound))。我是否需要首先将焦点更改到新选项卡?我该怎么办?

ruby selenium-chromedriver capybara
1个回答
0
投票

制表符在Capybara中被视为新窗口,因此您需要使用Capybaras window 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
© www.soinside.com 2019 - 2024. All rights reserved.