Watir-webdriver_ruby元素操作与定位

元素定位

browser.element(how,what)

常用元素
*button          e.g: browser.button(:id,'su').click()
*checkbox
*text_field     e.g:browser.text_field(:id,'kw').set('watir-webdriver')
*form
*frame
*div
*image
*link
*radio
*select
*table
*text_area

*file_field


元素的操作:
*click
*set
*clear
*select
*double_click
*hover
*right_click
*send_keys
*focus
*flash

*fire_event

**Frames
Frames are fairly easy to deal with in Watir-WebDriver, just use them the same way as any other element.
b.frame(:id => "content_ifr").send_keys "hello world"

实例:

1. browser.a(:id => "foo") == browser.a(:id => "foo")
#=> true

2. browser.a(:id => "foo").attribute_value "href"
#=> "http://watir.com"

3.browser.a(:id => "foo").double_click
4.browser.div(:id => "draggable").drag_and_drop_by 100, -200
5.a = browser.div(:id => "draggable")
b = browser.div(:id => "droppable")
a.drag_and_drop_on b
6.browser.a(:id => "foo").fire_event :click
browser.a(:id => "foo").fire_event "mousemove"
browser.a(:id => "foo").fire_event "onmouseover"
7.browser.div(:id => "draggable").flash
8.browser.a(:id => "foo").hover
9.browser.div(:id => "foo").html
#=> "<a>Click</a>"
10.browser.a(:id => "foo").right_click
11.browser.div(:id => "foo").send_keys "Watir", :return
12.browser.a(:id => "foo").style
#=> "display: block"
browser.a(:id => "foo").style "display"
#=> "block"
13.browser.element(:xpath => "//input[@type='submit']").to_subtype
#=> #<Watir::Button>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值