Class: AutomationObject::Driver::SeleniumAdapter::Element
- Inherits:
-
Proxy::Proxy
- Object
- Proxy::Proxy
- AutomationObject::Driver::SeleniumAdapter::Element
- Includes:
- CommonSelenium::Element
- Defined in:
- lib/automation_object/driver/selenium_adapter/element.rb
Overview
Element proxy for Selenium Conform Selenium element interface to what's expected of the Driver Port
Instance Method Summary collapse
-
#initialize(driver, element) ⇒ Element
constructor
A new instance of Element.
-
#scroll_into_view ⇒ void
Scroll the element into view.
Methods included from CommonSelenium::Element
#attribute, #clear, #click, #content, #hover, #href, #id, #invisible?, #send_keys, #submit, #switch_to_iframe, #text, #visible?
Methods included from CommonSelenium::ElementGeometry
#box_coordinates, #collides_with_element?, #element_center, #height, #location, #size, #width, #x, #y
Methods inherited from Proxy::Proxy
Constructor Details
#initialize(driver, element) ⇒ Element
Returns a new instance of Element
13 14 15 16 |
# File 'lib/automation_object/driver/selenium_adapter/element.rb', line 13 def initialize(driver, element) @driver = driver @subject = element end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AutomationObject::Proxy::Proxy
Instance Method Details
#scroll_into_view ⇒ void
This method returns an undefined value.
Scroll the element into view
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/automation_object/driver/selenium_adapter/element.rb', line 20 def scroll_into_view @subject.location_once_scrolled_into_view element_location = location scroll_position = @driver.scroll_position middle_y_bounds = scroll_position[:y] + @driver.inner_window_height / 2 if middle_y_bounds > element_location.y # Add y_difference = middle_y_bounds - element_location.y scroll_y_position = scroll_position[:y] - y_difference else # Subtract y_difference = element_location.y - middle_y_bounds scroll_y_position = scroll_position[:y] + y_difference end # Get the element to halfway scroll_x_position = element_location.x.to_f javascript_string = "return window.scroll(#{scroll_x_position}, #{scroll_y_position});" @driver.execute_script(javascript_string) end |