class Watigiri::Locators::Element::Locator
Private Instance Methods
filter_elements(elements)
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 21 def filter_elements(elements) element_matcher.nokogiri = true found = [element_matcher.match(elements, match_values, @filter)].flatten.compact se_elements = nokogiri_to_selenium(elements, found) @filter == :first ? se_elements.first : se_elements end
match_regexp?()
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 47 def match_regexp? @match_regexp ||= Watigiri.match_regexp? && match_values.all? do |k, v| v.is_a?(Regexp) && !k.to_s.include?('visible') && !k.to_s.include?('label') end && !match_values.empty? end
matching_elements()
click to toggle source
Calls superclass method
# File lib/watigiri/locators/element/locator.rb, line 7 def matching_elements return super unless use_nokogiri? # Element should be using `#fragment` instead of `#inner_html`, but can't because of # https://github.com/sparklemotion/nokogiri/issues/572 command = locator_scope.is_a?(Watir::Browser) ? :html : :inner_html args = wd_locator.to_a.flatten args[0] = "at_#{args[0]}" unless match_regexp? result = populate_doc command, *args match_regexp? ? filter_elements(result) : result end
nokogiri_to_selenium(elements, found)
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 54 def nokogiri_to_selenium(elements, found) locator_scope.elements(wd_locator).map.each_with_index do |el, idx| el.wd if found&.include? elements[idx] end.compact end
populate_doc(command, key, value)
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 38 def populate_doc(command, key, value) @query_scope.doc ||= Nokogiri::HTML(locator_scope.send(command)).tap { |d| d.css('script').remove } @query_scope.doc.send(key, value) end
use_nokogiri?()
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 29 def use_nokogiri? @nokogiri = @built.delete(:nokogiri) # Neither CSS nor XPath locator found return false if wd_locator.empty? || @selector.key?(:adjacent) @nokogiri && match_values.empty? || match_regexp? end
wd_locator()
click to toggle source
# File lib/watigiri/locators/element/locator.rb, line 43 def wd_locator @wd_locator ||= @built.select { |k, _v| %i[css xpath].include?(k) } end