Ruby学习笔记(23)_Capybara Finders

All

#all([kind = Capybara.default_selector], locator = nil, options = {}) ⇒ Capybara::Result
#all([kind = Capybara.default_selector], locator = nil, options = {}) {|element| ... } ⇒ Capybara::Result
Also known as: find_all

Find all elements on the page matching the given selector and options.

Both XPath and CSS expressions are supported, but Capybara does not try to automatically distinguish between them. The following statements are equivalent:

page.all(:css, 'a#person_123')
page.all(:xpath, './/a[@id="person_123"]')

The set of found elements can further be restricted by specifying options. It’s possible to select elements by their text or visibility:

page.all('a', text: 'Home')
page.all('#menu li', visible: true)

语法:

#all([kind = Capybara.default_selector], locator = nil, options = {}) {|element| ... } ⇒ Capybara::Result

Yield Parameters:
element (Capybara::Node::Element) — The element being considered for inclusion in the results

Parameters:
  • kind (Symbol) — Optional selector type (:css, :xpath, :field, etc.) - Defaults to Capybara.default_selector
  • locator (String) (defaults to: nil) — The selector
  • options (Hash) (defaults to: {}) — a customizable set of options
Options Hash (options):
  • text (String, Regexp) — Only find elements which contain this text or match this regexp
  • exact_text (String, Boolean) — default: Capybara.exact_text — When String the string the elements contained text must match exactly, when Boolean controls whether the :text option must match exactly
  • visible (Boolean, Symbol) — Only find elements with the specified visibility:
    true - only finds visible elements.
    false - finds invisible and visible elements.
    :all - same as false; finds visible and invisible elements.
    :hidden - only finds invisible elements.
    :visible - same as true; only finds visible elements.
  • count (Integer) — Exact number of matches that are expected to be found
  • maximum (Integer) — Maximum number of matches that are expected to be found
  • minimum (Integer) — Minimum number of matches that are expected to be found
  • between (Range) — Number of matches found must be within the given range
  • exact (Boolean) — Control whether is expressions in the given XPath match exactly or partially
  • wait (Integer) — default: Capybara.default_max_wait_time — The time to wait for element count expectations to become true
Return

(Capybara::Result) — A collection of found elements(数组)


Find

语法:

#find(*args, &optional_filter_block) ⇒ Capybara::Node::Element

Find an Element based on the given arguments. find will raise an error if the element is not found.

If the driver is capable of executing JavaScript, find will wait for a set amount of time and continuously retry finding the element until either the element is found or the time expires. The length of time find will wait is controlled through Capybara.default_max_wait_time and defaults to 2 seconds. find takes the same options as all.

page.find('#foo').find('.bar')
page.find(:xpath, './/div[contains(., "bar")]')
page.find('li', text: 'Quox').click_link('Delete')

find_button

语法:

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

Find a button on the page. 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.
  • disabled (Boolean, Symbol) — default: false — Match disabled button?
    true - only finds a disabled button
    false - only finds an enabled button
    :all - finds either an enabled or disabled button

  • id (String) — Match buttons with the id provided

  • title (String) — Match buttons with the title provided
  • value (String) — Match buttons with the value provided
  • class (String, Array) — Match links that match the class(es) provided

find_field

语法:

#find_field([locator], options = {}) ⇒ Capybara::Node::Element
Also known as: field_labeled

Find a form field on the page. The field can be found by its name, id or label text.

Options Hash (options):
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • checked (Boolean) — Match checked field?
  • unchecked (Boolean) — Match unchecked field?
  • disabled (Boolean, Symbol) — default: false — Match disabled field?
  • true - only finds a disabled field
  • false - only finds an enabled field
  • :all - finds either an enabled or disabled field
  • readonly (Boolean) — Match readonly field?
  • with (String, Regexp) — Value of field to match on
  • type (String) — Type of field to match on
  • 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
  • Match (String, Array) — fields that match the class(es) passed

语法:

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

Find a link on the page. The link can be found by its id or text.

Options Hash (options):
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • href (String, Regexp, nil) — Value to match against the links href, if nil finds link placeholders ( elements with no href attribute)
  • id (String) — Match links with the id provided
  • title (String) — Match links with the title provided
  • alt (String) — Match links with a contained img element whose alt matches
  • class (String, Array) — Match links that match the class(es) provided
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值