Class: AutomationObject::Driver::NokogiriAdapter::Element
- Inherits:
-
Object
- Object
- AutomationObject::Driver::NokogiriAdapter::Element
- Defined in:
- lib/automation_object/driver/nokogiri_adapter/element.rb
Overview
Element for nokogiri Conforms to Element interface for an XML source using Nokogiri
Instance Method Summary collapse
-
#attribute(key, value = nil) ⇒ String?
Set or Get attribute.
-
#box_coordinates ⇒ BoxCoordinates
:x1, :x2, :y1, :y2 coordinates of a box.
-
#clear ⇒ void
Clear the element field.
-
#click ⇒ void
Perform a click action on the element.
-
#collides_with_element?(_second_element_object, _collision_tolerance = false) ⇒ Boolean
Element collides with other.
-
#content ⇒ String?
Content of element.
-
#element_center ⇒ Point
:x, :y coordinates.
-
#height ⇒ Numeric
Height of element.
-
#hover ⇒ void
Hover over element.
-
#href ⇒ String
Href of element.
-
#id ⇒ String
Id of element.
-
#initialize(driver, element) ⇒ Element
constructor
A new instance of Element.
- #invisible? ⇒ Boolean
-
#location ⇒ Point
Get the location.
-
#scroll_into_view ⇒ void
Scroll the element into view.
-
#send_keys(string) ⇒ void
Type into an element.
-
#size ⇒ Dimension
Get the size of an element.
-
#submit ⇒ void
Perform a submit action on an element.
-
#switch_to_iframe ⇒ void
Helper method to switch to this element's iframe.
-
#text ⇒ String?
Text of element.
- #visible? ⇒ Boolean
-
#width ⇒ Numeric
Width of element.
-
#x ⇒ Numeric
X position of element.
-
#y ⇒ Numeric
Y position of element.
Constructor Details
#initialize(driver, element) ⇒ Element
Returns a new instance of Element
14 15 16 17 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 14 def initialize(driver, element) @driver = driver @subject = element end |
Instance Method Details
#attribute(key, value = nil) ⇒ String?
Set or Get attribute
23 24 25 26 |
# 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 ⇒ BoxCoordinates
Returns :x1, :x2, :y1, :y2 coordinates of a box
125 126 127 |
# 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 ⇒ void
This method returns an undefined value.
Clear the element field
60 61 62 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 60 def clear @subject['value'] = '' end |
#click ⇒ void
This method returns an undefined value.
Perform a click action on the element
92 93 94 95 96 97 |
# 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) ⇒ Boolean
Returns element collides with other
132 133 134 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 132 def collides_with_element?(_second_element_object, _collision_tolerance = false) false end |
#content ⇒ String?
Content of element
46 47 48 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 46 def content @subject.content end |
#element_center ⇒ Point
Returns :x, :y coordinates
120 121 122 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 120 def element_center Point.new(x: 0, y: 0) end |
#height ⇒ Numeric
Returns height of element
115 116 117 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 115 def height 0 end |
#hover ⇒ void
This method returns an undefined value.
Hover over element
138 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 138 def hover; end |
#href ⇒ String
Returns href of element
34 35 36 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 34 def href @subject['href'] end |
#id ⇒ String
Returns id of element
29 30 31 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 29 def id @subject['id'] end |
#invisible? ⇒ Boolean
68 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 68 def invisible?; end |
#location ⇒ Point
Get the location
72 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 72 def location; end |
#scroll_into_view ⇒ void
This method returns an undefined value.
Scroll the element into view
88 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 88 def scroll_into_view; end |
#send_keys(string) ⇒ void
This method returns an undefined value.
Type into an element
52 53 54 55 56 |
# 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 ⇒ Dimension
Get the size of an element
76 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 76 def size; end |
#submit ⇒ void
This method returns an undefined value.
Perform a submit action on an element
80 81 82 83 84 |
# 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 ⇒ void
This method returns an undefined value.
Helper method to switch to this element's iframe
142 143 144 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 142 def switch_to_iframe # TODO: finish end |
#text ⇒ String?
Text of element
40 41 42 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 40 def text @subject.content end |
#visible? ⇒ Boolean
65 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 65 def visible?; end |
#width ⇒ Numeric
Returns width of element
110 111 112 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 110 def width 0 end |
#x ⇒ Numeric
Returns x position of element
100 101 102 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 100 def x 0 end |
#y ⇒ Numeric
Returns y position of element
105 106 107 |
# File 'lib/automation_object/driver/nokogiri_adapter/element.rb', line 105 def y 0 end |