Watir-webdriver 替换 watir 的attach功能
watir:
require'watir'
@browser=Watir::IE.attatch(:url,/browser_url/)
watir-webdriver:
require'watir-webdriver
@browser=Watir::Browser.new(:chrome) #以 chrome为例
#浏览器打开后 即点击自己想要的操作,以新窗口打开页面时如下操作
@browser.window(:url,/new_url/).use
#此后新窗口的元素 也可通过browser定位
附:其他browser.window应用
@browser.window(省略).close #close all the window
@browser.window(省略).current? # true is the window is exist
@browser.window(省略).hash #return hashid
@browser.window(省略).inspect #return window info
@browser.window(省略).title #return window title
@browser.window(省略).url #return window url
@browser.window(省略).use #use new window
watir-webdriver弹窗(alert\confirm\prompt 都对应元素名称为 alert)
requre 'watir-webdriver/extensions/alerts'
@browser.alert.exists? #true 存在
@browser.alert.text
@browser.alert.ok #对应所有弹窗的确定按钮
@browser.alert.close #等价于所有弹窗的取消操作
@browser.alert.set "this is for prompt" #弹窗类型为prompt时文本输入框文字输入
@browser.alert.selector_string#return 'alert'
本文介绍如何使用 Watir-Webdriver 替代 Watir 的 attach 功能,并提供了示例代码。此外还介绍了如何处理浏览器窗口切换及弹窗操作。
212

被折叠的 条评论
为什么被折叠?



