当前位置: 首页 > 工具软件 > WebElements > 使用案例 >

Webdriver_Web Elements

刘狐若
2023-12-01

All HTML elements are supported by Watir-WebDriver. Some examples are below:


Text Fields
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
t = b.text_field :id => 'entry_0'
t.exists?
t.set 'your name'
t.value

Select Lists – Combos
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
s = b.select_list :id => 'entry_1'
s.select 'Ruby'
s.selected_options

Radios
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
r = b.label(:text => 'What is ruby?').parent.radio :value => 'A gem'
r.exists?
r.set
r.set?

Checkboxes
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
c = b.label(:text => 'What versions of ruby?').parent.checkbox :value => '1.9.2'
c.exists?
c.set
c.set?

Buttons
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
btn = b.button :value, 'Submit'
btn.exists?
btn.click

Links
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
l = b.link :text => 'Google Docs'
l.exists?
l.click

Divs & Spans
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
d = b.div :class => 'ss-form-desc ss-no-ignore-whitespace'
d.exists?
d.text
s = b.span :class => 'ss-powered-by'
s.exists?
s.text
 类似资料:

相关阅读

相关文章

相关问答