Module: Unobtainium::MultiFind::DriverModule
- Defined in:
- lib/unobtainium-multifind/multifind.rb
Overview
Driver module implementing multi find functionality.
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options. This hash is also used to detect if any of the Hashes passed to #multifind is an options Hash; it is considered one if it contains any of the keys specified here.
{ # If true, raises on error instead of returning nil raise_on_error: false, # If true, returns the error object instead of nil return_errors: false, # If :all is specified, all results are returned. # If :first is specified, the first non-error result is # returned. # If :last is specified, the last non-error result is # returned. find: :all, # Defaults to only finding :displayed? elements. You can use any method # that Selenium::WebDriver::Element responds to, or :exists? if you only # care whether the element exists. check_element: :displayed?, }.freeze
Instance Attribute Summary collapse
-
#multifind_options ⇒ Object
Current options for multifind.
Class Method Summary collapse
-
.matches?(impl) ⇒ Boolean
Returns true if the implementation has ‘#find_element`, false otherwise.
Instance Method Summary collapse
-
#multifind(*args) ⇒ Object
(also: #find)
Find multiple elements.
Instance Attribute Details
#multifind_options ⇒ Object
Current options for multifind
52 53 54 |
# File 'lib/unobtainium-multifind/multifind.rb', line 52 def @multifind_options end |
Class Method Details
.matches?(impl) ⇒ Boolean
Returns true if the implementation has ‘#find_element`, false otherwise.
45 46 47 |
# File 'lib/unobtainium-multifind/multifind.rb', line 45 def matches?(impl) return impl.respond_to?(:find_element) end |
Instance Method Details
#multifind(*args) ⇒ Object Also known as: find
Find multiple elements. Each argument is a Hash of selector options that are passed to #find_element. If one argument contains keys from the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash for the #multifind method.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/unobtainium-multifind/multifind.rb', line 62 def multifind(*args) # Parse options , selectors = (*args) # Now find elements results = [] selectors.each do |selector| begin results << find_element(selector) rescue ::Selenium::WebDriver::Error::NoSuchElementError => err if [:raise_on_error] raise end if [:return_errors] results << err next end results << nil end end # Filter results, if necessary return multifind_filter_results(, results) end |