watir-webdriver 是否有 watir::ie.attach 的替代方案,因为 webdriver 不支持 Attach

发布于 2024-11-04 03:06:09 字数 781 浏览 5 评论 0原文

我有一个网站,仅在支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忘年祭陌 2024-11-11 03:06:09

“window”方法是 ie.attach 的替代方法。 Webdriver可以用window方法来处理自己打开的窗口。

b.link(:href,/server\/getPage/).click
b.window(:url,/server\/getPage/i).use do
  b.link(:id,"btn_MAP").click
end

您可以在窗口方法块中处理弹出的窗口。如果您想继续处理弹出窗口,请在没有块的情况下使用它,例如 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.

b.link(:href,/server\/getPage/).click
b.window(:url,/server\/getPage/i).use do
  b.link(:id,"btn_MAP").click
end

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

新一帅帅 2024-11-11 03:06:09

@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

时光沙漏 2024-11-11 03:06:09

您是否尝试过将该网站设为浏览器的默认主页?

这可能会阻止您进行附加操作。

have you tried making the website the default homepage for the browser?

that might prevent you from having to do an attach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文