Class: PageObjectify::DOM

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/page-objectify/dom.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(doc) ⇒ DOM

Returns a new instance of DOM.



8
9
10
11
12
13
14
15
16
17
# File 'lib/page-objectify/dom.rb', line 8

def initialize(doc)
  @doc = doc
  @accessors = []
  @tags_to_accessors = {}
  @input_types_to_accessors = {}
  @types = %i(text password checkbox button image reset submit radio hidden file)
  @ignored_tags = %i(meta style body) # that could possibly have an HTML id

  generate_mapping
end

Instance Method Details

#to_accessorsObject



19
20
21
22
23
24
25
26
27
# File 'lib/page-objectify/dom.rb', line 19

def to_accessors
  # Grab only nodes with non-empty HTML id
  @doc.xpath("//*[@id!='']").each do |node|
    accessor = accessor_for(node)
    @accessors << { accessor: accessor, id: node.attributes["id"].to_s } if accessor
  end
  logger.info "DOM nodes convertable to PageObject::Accessors: #{@accessors.count}"
  @accessors
end