Method: Capybara::Node::Matchers#has_selector?
- Defined in:
- lib/capybara/node/matchers.rb
#has_selector?(*args, **options, &optional_filter_block) ⇒ Boolean
Checks if a given selector is on the page or a descendant of the current node.
page.has_selector?('p#foo')
page.has_selector?(:xpath, './/p[@id="foo"]')
page.has_selector?(:foo)
By default it will check if the expression occurs at least once, but a different number can be specified.
page.has_selector?('p.foo', count: 4)
This will check if the expression occurs exactly 4 times.
It also accepts all options that Finders#all accepts,
such as :text
and :visible
.
page.has_selector?('li', text: 'Horse', visible: true)
#has_selector? can also accept XPath expressions generated by the XPath gem:
page.has_selector?(:xpath, XPath.descendant(:p))
38 39 40 |
# File 'lib/capybara/node/matchers.rb', line 38 def has_selector?(*args, **, &optional_filter_block) make_predicate() { assert_selector(*args, , &optional_filter_block) } end |