Class: Capybara::Selenium::Node
- Inherits:
-
Driver::Node
- Object
- Driver::Node
- Capybara::Selenium::Node
- Defined in:
- lib/capybara/core_ext/selenium/node.rb
Overview
Selenium specific implementation of the Capybara::Driver::Node API
Instance Method Summary collapse
-
#location ⇒ Selenium::WebDriver::Point
Returns the element absolute location on the page.
-
#on_screen?(fully) ⇒ Boolean
Validates if the element on the displayed part of the page (screen!).
-
#scroll_into_view! ⇒ Nil
Scrolls an element into view and return the element to allow method chaining.
-
#size ⇒ Selenium::WebDriver::Dimension
Returns the size of this element.
-
#x_end ⇒ Object
Returns the end of the X element location on the page.
-
#x_origin ⇒ Object
Returns the element X location on the page.
-
#y_end ⇒ Object
Returns the end of the Y element location on the page.
-
#y_origin ⇒ Object
Returns the element Y location on the page.
Instance Method Details
#location ⇒ Selenium::WebDriver::Point
Returns the element absolute location on the page
41 42 43 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 41 def location native.location end |
#on_screen?(fully) ⇒ Boolean
Validates if the element on the displayed part of the page (screen!)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 17 def on_screen?(fully) raise ArgumentError, 'on_screen argument should be true or false' unless [true, false].include?(fully) screen_position_x = driver.execute_script('return window.scrollX;') screen_position_y = driver.execute_script('return window.scrollY;') window_size = driver.browser.manage.window.size screen_size_width = window_size.width screen_size_height = window_size.height if fully on_screen_x = (x_origin < (screen_position_x + screen_size_width) and x_end < (screen_position_x + screen_size_width)) on_screen_y = (y_origin < (screen_position_y + screen_size_height) and y_end < (screen_position_y + screen_size_height)) else #partially on_screen_x = location.x < (screen_position_x + screen_size_width) on_screen_y = location.y < (screen_position_y + screen_size_height) end on_screen_x and on_screen_y end |
#scroll_into_view! ⇒ Nil
Scrolls an element into view and return the element to allow method chaining
7 8 9 10 11 12 13 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 7 def scroll_into_view! script = <<-JS arguments[0].scrollIntoView(false); JS driver.execute_script(script, native) end |
#size ⇒ Selenium::WebDriver::Dimension
Returns the size of this element
47 48 49 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 47 def size native.size end |
#x_end ⇒ Object
Returns the end of the X element location on the page
59 60 61 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 59 def x_end @x_end ||= (x_origin + size.width).to_i end |
#x_origin ⇒ Object
Returns the element X location on the page
53 54 55 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 53 def x_origin @x_origin ||= (location.x).to_i end |
#y_end ⇒ Object
Returns the end of the Y element location on the page
71 72 73 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 71 def y_end @y_end ||= (y_origin + size.height).to_i end |
#y_origin ⇒ Object
Returns the element Y location on the page
65 66 67 |
# File 'lib/capybara/core_ext/selenium/node.rb', line 65 def y_origin @y_origin ||= (location.y).to_i end |