watir-webdriver 是否有 watir::ie.attach 的替代方案,因为 webdriver 不支持 Attach
我有一个网站,仅在支持 Webkit 的浏览器(Google Chrome、Safari)中呈现。我使用的是 Google Chrome,因为我使用的是 Windows 7。
我使用 Watir-WebDriver 来实现相同的自动化。
问题:当我单击浏览器窗口上的按钮时,会启动另一个窗口,并且单击后内容将在新的浏览器窗口中呈现。我需要一种方法来识别这个新的浏览器窗口,以便能够继续进行测试。我一直在各种论坛上阅读,但没有得到任何确定的答案/解决方案。
问:watir-webdriver 是否有 watir::ie.attach 的替代方案,因为 Watir-Webdriver 不支持 Attach
示例代码:
require "rubygems"
require "watir-webdriver"
require "selenium-webdriver"
b = Watir::Browser.new(:chrome)
website = "http://xyz.com"
#a new browser is launched and the website is opened
b.goto(website)
#this opens a new browser window
b.link(:xpath,"/html/body/div/ul/li/a").click
#there is a button called "MAP" on the new browser window
b.link(:id,"btn_MAP")
#this gives an error, unknown link
I have a website which is only rendered in Webkit enabled browser (Google Chrome, Safari). I am using Google Chrome since I am on Windows 7.
I am using Watir-WebDriver to automate the same.
Issue: When I click on a button on the browser window, is launches another window and post click content is rendered in the new browser window. I need a way to be able to Identify this new browser window, in-order to be able to proceed with my testing. I have been reading on various forums, but not getting any certain answer/solution.
Q: Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on Watir-Webdriver
Sample code:
require "rubygems"
require "watir-webdriver"
require "selenium-webdriver"
b = Watir::Browser.new(:chrome)
website = "http://xyz.com"
#a new browser is launched and the website is opened
b.goto(website)
#this opens a new browser window
b.link(:xpath,"/html/body/div/ul/li/a").click
#there is a button called "MAP" on the new browser window
b.link(:id,"btn_MAP")
#this gives an error, unknown link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“window”方法是 ie.attach 的替代方法。 Webdriver可以用window方法来处理自己打开的窗口。
您可以在窗口方法块中处理弹出的窗口。如果您想继续处理弹出窗口,请在没有块的情况下使用它,例如 window(:url,/foobar/)。use
另请参阅:
http://groups.google.com/group/watir-general/browse_thread /线程/232df221602d4cfb
"window" method is the alternative for ie.attach. Webdriver can handle the window opened by itself with window method.
you can handle popped up windows in the window method block. If you want to keep handling popped up window, use it without block, like window(:url,/foobar/).use
see also:
http://groups.google.com/group/watir-general/browse_thread/thread/232df221602d4cfb
@Yutaka:非常感谢您的所有帮助,它引导我使用类似以下的内容并且它有效!
b.link(:xpath,"/html/body/div/ul/li/a").click
c = b.window(:url,"http:\/\/server\/getPage\/67\/1354 ")
c.use
b.link(:id,"btn_MAP").click
@Yutaka: Thanks a lot for all your help it lead me to use something like the following and it worked!
b.link(:xpath,"/html/body/div/ul/li/a").click
c = b.window(:url,"http:\/\/server\/getPage\/67\/1354")
c.use
b.link(:id,"btn_MAP").click
您是否尝试过将该网站设为浏览器的默认主页?
这可能会阻止您进行附加操作。
have you tried making the website the default homepage for the browser?
that might prevent you from having to do an attach.