class AutomationObject::Driver::NokogiriAdapter::Element

Element for nokogiri Conforms to Element interface for an XML source using Nokogiri

Public Class Methods

new(driver, element) click to toggle source

@param [AutomationObject::Driver::NokogiriAdapter::Driver] driver @param [Nokogiri::XML::Node] element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 14
def initialize(driver, element)
  @driver = driver
  @subject = element
end

Public Instance Methods

attribute(key, value = nil) click to toggle source

Set or Get attribute @param key [String] key of element @param value [String, nil] set value or leave blank @return [String, nil]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 23
def attribute(key, value = nil)
  @subject[key] = value if value
  @subject[key]
end
box_coordinates() click to toggle source

@return [BoxCoordinates] :x1, :x2, :y1, :y2 coordinates of a box

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 125
def box_coordinates
  BoxCoordinates.new(x1: 0, y1: 0, x2: 0, y2: 0)
end
clear() click to toggle source

Clear the element field @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 60
def clear
  @subject['value'] = ''
end
click() click to toggle source

Perform a click action on the element @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 92
def click
  @driver.session.request(:get, href, {}, attribute('target') == '_blank') if href && @subject['tag'] == 'a'

  # In case it's a button inside the form
  submit if find_form(@subject)
end
collides_with_element?(_second_element_object, _collision_tolerance = false) click to toggle source

@param _second_element_object [Object] element to compare to @param _collision_tolerance [Numeric, FalseClass] pixel tolerance of collisions @return [Boolean] element collides with other

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 132
def collides_with_element?(_second_element_object, _collision_tolerance = false)
  false
end
content() click to toggle source

Content of element @return [String, nil]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 46
def content
  @subject.content
end
element_center() click to toggle source

@return [Point] :x, :y coordinates

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 120
def element_center
  Point.new(x: 0, y: 0)
end
height() click to toggle source

@return [Numeric] height of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 115
def height
  0
end
hover() click to toggle source

Hover over element @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 138
def hover; end
href() click to toggle source

@return [String] href of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 34
def href
  @subject['href']
end
id() click to toggle source

@return [String] id of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 29
def id
  @subject['id']
end
invisible?() click to toggle source

@return [Boolean]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 68
def invisible?; end
location() click to toggle source

Get the location @return [Point]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 72
def location; end
scroll_into_view() click to toggle source

Scroll the element into view @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 88
def scroll_into_view; end
send_keys(string) click to toggle source

Type into an element @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 52
def send_keys(string)
  @subject['value'] = @subject[key] + string if @subject['value'].is_a?(String)

  @subject['value'] = value
end
size() click to toggle source

Get the size of an element @return [Dimension]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 76
def size; end
submit() click to toggle source

Perform a submit action on an element @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 80
def submit
  form_element = find_form(@subject)
  raise NoSuchElementError unless form_element
  @driver.session.request(form.request_method, form.url, form.params, form_element.new_window?)
end
switch_to_iframe() click to toggle source

Helper method to switch to this element's iframe @return [void]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 142
def switch_to_iframe
  # TODO: finish
end
text() click to toggle source

Text of element @return [String, nil]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 40
def text
  @subject.content
end
visible?() click to toggle source

@return [Boolean]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 65
def visible?; end
width() click to toggle source

@return [Numeric] width of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 110
def width
  0
end
x() click to toggle source

@return [Numeric] x position of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 100
def x
  0
end
y() click to toggle source

@return [Numeric] y position of element

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 105
def y
  0
end

Private Instance Methods

find_form(element) click to toggle source

@return [AutomationObject::Driver:NokogiriAdapter::Form]

# File lib/automation_object/driver/nokogiri_adapter/element.rb, line 149
def find_form(element)
  return nil unless element

  return AutomationObject::Driver::NokogiriAdapter::Form.new(element) if element.name == 'form'
  find_form(element.parent)
end