Ruby学习笔记(23)_Capybara Actions

attach_file

语法:

#attach_file(locator, path, options = {}) ⇒ Capybara::Node::Element

Find a file field on the page and attach a file given its path. The file field can be found via its name, id or label text.

page.attach_file(locator, '/path/to/file.png')
Parameters:
  • locator (String) — Which field to attach the file to
  • path (String) — The path of the file that will be attached, or an array of paths
  • options (Hash) (defaults to: {}) — a customizable set of options
Options Hash (options):
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • match (Symbol) — default: Capybara.match — The matching strategy to use (:one, :first, :prefer_exact, :smart).
  • exact (Boolean) — default: Capybara.exact — Match the exact label name/contents or accept a partial match.
  • multiple (Boolean) — Match field which allows multiple file selection
  • id (String) — Match fields that match the id attribute
  • name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • make_visible (true, Hash) — A Hash of CSS styles to change before attempting to attach the file, if true { opacity: 1, display: ‘block’, visibility: ‘visible’ } is used (may not be supported by all drivers)
Returns:

(Capybara::Node::Element) — The file field element


check

语法:

#check([locator], options) ⇒ Capybara::Node::Element

Find a check box and mark it as checked. The check box can be found via name, id or label text.

page.check('German')
Options Hash (options):
  • :option (String) — Value of the checkbox to select
  • id (String) — Match fields that match the id attribute
  • name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • :allow_label_click (Boolean) — default: Capybara.automatic_label_click — Attempt to click the label to toggle state if element is non-visible.
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
Returns:

(Capybara::Node::Element) — The element checked or the label clicked

uncheck
page.uncheck('German')

choose

语法:

#choose([locator], options) ⇒ Capybara::Node::Element

Find a radio button and mark it as checked. The radio button can be found via name, id or label text.

page.choose('Male')
Options Hash (options):
  • :option (String) — Value of the radio_button to choose
  • :id (String) — Match fields that match the id attribute
  • :name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • :allow_label_click (Boolean) — default: Capybara.automatic_label_click — Attempt to click the label to toggle state if element is non-visible.
Returns:

(Capybara::Node::Element) — The element chosen or the label clicked


click_button

#click_button([locator], options) ⇒ Capybara::Node::Element

Finds a button on the page and clicks it. This can be any element of type submit, reset, image, button or it can be a element. All buttons can be found by their id, value, or title. elements can also be found by their text content, and image elements by their alt attribute

Options Hash (options):

wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.


语法:

#click_link([locator], options) ⇒ Capybara::Node::Element

Finds a link by id, text or title and clicks it. Also looks at image alt text inside the link.

Options Hash (options):

wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.


fill_in

语法:

#fill_in([locator], options = {}) ⇒ Capybara::Node::Element

Locate a text field or text area and fill it in with the given text The field can be found via its name, id or label text.

page.fill_in 'Name', with: 'Bob'
Options Hash (options):
  • wait (false, Numeric) — default: Capybara.default_max_wait_time —
    Maximum time to wait for matching element to appear.

  • :with (String) — The value to fill in - required

  • :fill_options (Hash) — Driver specific options regarding how to fill fields
  • :currently_with (String) — The current value property of the field to fill in
  • :multiple (Boolean) — Match fields that can have multiple values?
  • :id (String) — Match fields that match the id attribute
  • :name (String) — Match fields that match the name attribute
  • :placeholder (String) — Match fields that match the placeholder attribute
  • :class (String, Array) — Match links that match the class(es) provided

select

语法:

#select(value, options = {}) ⇒ Capybara::Node::Element

If :from option is present, select finds a select box on the page and selects a particular option from it. Otherwise it finds an option inside current scope and selects it. If the select box is a multiple select, select can be called multiple times to select more than one option. The select box can be found via its name, id or label text. The option can be found by its text.

page.select 'March', from: 'Month'
Parameters:
  • value (String) — Which option to select
  • options (Hash) (defaults to: {}) — a customizable set of options
Options Hash (options):
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • :from (String) — The id, name or label of the select box
Returns:

(Capybara::Node::Element) — The option element selected

unselect
page.unselect 'March', from: 'Month'

获取element属性值

find("#username")[:value]
#返回value的值
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值