有没有办法使用 watir-webdriver 每次点击 Chrome 上的链接时不打开新窗口
我正在尝试使用 Google Chrome 来自动测试用 JavaScript 为 iPhone 开发的移动应用程序,由于它是基于 Webkit 的,所以只有 Safari 和 Google Chrome 可以呈现内容,所以我没有其他选择,只能使用 watir-webdriver。
我做了很多研究,试图找到一种在 Google Chrome 上实现自动化的解决方案,而我能得到的最接近的是 Watir-WebDriver。
我有以下代码:
require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.new(:chrome)
website = "http://xxx.yyy.zzz"
browser.goto(website)
browser.link(:xpath,"/html/body/div/ul/li/a").click #step1
browser.link(:xpath,"/html/body/div/div[2]/div/ul/li//*[@id=btn_WEBURL]").click #step2
一旦执行#step1,内容就会在新的浏览器窗口中打开,这会导致:
C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.2/lib/watir-
webdriver/elements/element.rb:241:in `assert_exists': unable to locate element,
using {:xpath=>"/html/body/div/div[2]/div/ul/li//*[@id=btn_WEBURL]", :tag_name=>
"a"} (Watir::Exception::UnknownObjectException)
from C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2
.2/lib/watir-webdriver/elements/element.rb:69:in `click'
from ft.rb:13
有没有办法在每次单击 Chrome 上的链接时不打开新窗口,使用watir-webdriver。或者任何其他解决我的问题的方法。
谢谢
I am trying to using Google Chrome to automate my testing of a mobile app developed in JavaScript for iPhone, and since it is Webkit based only Safari and Google Chrome can render the content, so I have no other option then to use watir-webdriver.
I have done a lot of research in trying to find a solution to automate on Google Chrome and the closest I could get is with Watir-WebDriver.
I have the following code:
require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.new(:chrome)
website = "http://xxx.yyy.zzz"
browser.goto(website)
browser.link(:xpath,"/html/body/div/ul/li/a").click #step1
browser.link(:xpath,"/html/body/div/div[2]/div/ul/li//*[@id=btn_WEBURL]").click #step2
As soon as the #step1 is executed, the content is opened in a new browser window, which results in:
C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.2/lib/watir-
webdriver/elements/element.rb:241:in `assert_exists': unable to locate element,
using {:xpath=>"/html/body/div/div[2]/div/ul/li//*[@id=btn_WEBURL]", :tag_name=>
"a"} (Watir::Exception::UnknownObjectException)
from C:/Program Files/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.2
.2/lib/watir-webdriver/elements/element.rb:69:in `click'
from ft.rb:13
Is there a way to NOT open a new window every time I click on a link on Chrome, using watir-webdriver. Or any other solution to my problem.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以找到并使用另一个窗口:
查看更多示例:https://github。 com/jarib/watirspec/blob/watir2/window_switching_spec.rb
You can locate and use the other window:
see more examples: https://github.com/jarib/watirspec/blob/watir2/window_switching_spec.rb