Controlling new tab to operate using Watir? (Ruby)

眉间皱痕 提交于 2019-12-22 10:54:06

问题


I'm using watir for automated testing and after running through some tables, a chart then gets opened up in a new tab. But watir doesn't seem to recognise the new current tab and continues to search through the original browser tab.

Is there any way of telling watir which tab you want to be using?


回答1:


Watir does not care if a new page opens in a new window or in a new tab, so use window switching API to switch to the new tab:

browser.window(:title => "annoying popup").use do
  browser.button(:id => "close").click
end

More information: http://watirwebdriver.com/browser-popups/




回答2:


You can use this code

browser.windows.last.use

this will set watir focus to newly or last opened tab or window, and after completion of use of this new tab/window just tell watir to close that tab/window

browser.windows.last.close


来源:https://stackoverflow.com/questions/12457690/controlling-new-tab-to-operate-using-watir-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!