Watir: Watir-WebDriver对打开的浏览器attach操作

Watir-WebDriver对于已经打开的浏览器,没有办法进行Attach操作。
但是对于自动化操作浏览器过程中点击某链接,打开的新浏览器,是能够定位到的。
require 'watir-webdriver'
def attach_browser(browser, how, url)    
    browser.driver.switch_to.window(browser.driver.window_handles[0]) 
    browser.window(how, /#{url}/).use 
end 
 
ie2 = Watir::Browser.new :chrome
ie2.goto("http://www.baidu.com/more/")
ie2.link(:text, "网页").click
#p ie2.windows(:url, "http://www.baidu.com/")[-1]
ie3 = ie2.driver.switch_to.window("http://www.baidu.com/")
 puts ie3.links
原文地址:https://www.cnblogs.com/autotest/p/3262520.html