- Defined in:
#within(*find_args) ⇒ Object #within(a_node) ⇒ Object Also known as: within_element
Executes the given block within the context of a node.takes the same options as , as well as a block. For the duration of the block, any command to Capybara will be handled as though it were scoped to the given element.
within(:xpath, './/div[@id="delivery-address"]') do fill_in('Street', with: '12 Main Street') end
Just as with
#find, if multiple elements match the selector given to
, an error will be raised, and just as with
behaviour can be controlled through the
It is possible to omit the first parameter, in that case, the selector is assumed to be of the type set in.
within('div#delivery-address') do fill_in('Street', with: '12 Main Street') end
Note that a lot of uses ofcan be replaced more succinctly with chaining:
find('div#delivery-address').fill_in('Street', with: '12 Main Street')
341 342 343 344 345 346 347 348 349
# File 'lib/capybara/session.rb', line 341 def within(*args) new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args) begin scopes.push(new_scope) yield if block_given? ensure scopes.pop end end