class Marta::SimpleElementFinder::BasicFinder

That class is about simle element location strategy

@note It is believed that no user will use it The main idea is not to find an element but to find an xpath that leads to a valid element.

Public Class Methods

new(meth, requestor) click to toggle source
# File lib/marta/simple_element_finder.rb, line 21
def initialize(meth, requestor)
  @requestor = requestor
  @meth = meth
  @xpath = xpath_by_meth if !@meth.nil?
  @engine = requestor.engine
end

Public Instance Methods

collection?() click to toggle source

Maybe our element is defined as a collection?

# File lib/marta/simple_element_finder.rb, line 29
def collection?
  @meth['options']['collection']
end
find() click to toggle source

Main logic. We are returning a prefinded collection or subtyped prefind

# File lib/marta/simple_element_finder.rb, line 68
def find
  if collection?
    prefind_collection
  else
    subtype_of prefind
  end
end
forced_xpath?() click to toggle source

Maybe our element has user provided xpath?

# File lib/marta/simple_element_finder.rb, line 34
def forced_xpath?
  !@meth['options']['xpath'].nil?
end
prefind() click to toggle source

element prefinding

# File lib/marta/simple_element_finder.rb, line 48
def prefind
  @engine.element(xpath: @xpath)
end
prefind_collection() click to toggle source

collection prefinding

# File lib/marta/simple_element_finder.rb, line 53
def prefind_collection
  @engine.elements(xpath: @xpath)
end
subtype_of(element) click to toggle source

Transforming an element to a subtype

# File lib/marta/simple_element_finder.rb, line 58
def subtype_of(element)
  if @engine.element(xpath: @xpath).exists?
    @engine.element(xpath: @xpath).to_subtype
  else
    @engine.element(xpath: @xpath)
  end
end
xpath_by_meth() click to toggle source

Getting an xpath

# File lib/marta/simple_element_finder.rb, line 39
def xpath_by_meth
  if forced_xpath?
    @meth['options']['xpath']
  else
    XPathFactory.new(@meth, @requestor).generate_xpath
  end
end