[英]How to set WATIR focus on new window
I'm new to WATIR testing (and do I love it!) and have run into a wall on how to refocus my WATIR script to a newly opened window.. Here's my (simplified) script....我是 WATIR 测试的新手(我喜欢它吗!)并且遇到了关于如何将我的 WATIR 脚本重新聚焦到新打开的窗口的问题......这是我的(简化的)脚本......
#!/usr/bin/ruby
require 'rubygems'
require 'watir-webdriver'
browser=Watir::Browser.new
browser.goto("http://0:3050")
browser.text_field(:name,"userkey300203830").set("OKJHNB")
browser.button(:id, "interview48").click
puts "Expected Result:"
puts "A successful display of cars"
if browser.window(:title=>"300203830").exists?
puts " Test passed. New window opened!"
else
puts " Test Failed! No window found"
end
It all works right up to the end.这一切都有效到最后。 After the key "interview48" is clicked, a new window is opened with the title "300203830".
单击“interview48”键后,将打开一个标题为“300203830”的新窗口。 Looks like I find it but I just don't know how to now focus on that window.
看起来我找到了,但我现在不知道如何专注于该窗口。
browser.window(:title => "300203830").use do
# do something
end
More information: http://watir.github.io/docs/browser-popups/更多信息: http : //watir.github.io/docs/browser-popups/
Additionally for more than 2 windows you can use the following:此外,对于 2 个以上的窗口,您可以使用以下内容:
browser.windows[n].use
#n is variable for which window. #n 是哪个窗口的变量。 n will access them in order of opened or tabs from left to right
n 将按打开的顺序或从左到右的选项卡访问它们
browser.windows.last.use
browser.windows.first.use
You can use the above commands if you open a new window from first browser instance and would like to toggle between the two.如果您从第一个浏览器实例打开一个新窗口并希望在两者之间切换,则可以使用上述命令。
There are 3 primary selectors for windows: Windows 有 3 个主要选择器:
:title
- typically the easiest :title
- 通常是最简单的
:url
- often used with a Regexp value :url
- 通常与 Regexp 值一起使用
:element
- a unique element might be the least brittle (new as of Watir 6.18!) :element
- 一个独特的元素可能是最不脆弱的(Watir 6.18 的新元素!)
browser.window(title: 'new window') browser.window(url: /my_page.html/) browser.window(element: browser.div(id: 'my-element')) browser.window(title: 'new window') browser.window(url: /my_page.html/) browser.window(element: browser.div(id: 'my-element'))
Locating by index is no longer supported不再支持按索引定位
More information: Watir Browser Windows更多信息: Watir 浏览器 Windows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.