开发者

Is there a way to NOT open a new window every time I click on a link on Chrome, using watir-webdriver

开发者 https://www.devze.com 2023-02-26 05:25 出处:网络
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 ha

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 i开发者_如何学编程s 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


You can locate and use the other window:

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

see more examples: https://github.com/jarib/watirspec/blob/watir2/window_switching_spec.rb

0

精彩评论

暂无评论...
验证码 换一张
取 消