Module: Capybara::Selenium::Scroll
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/capybara/selenium/extensions/scroll.rb |
Constant Summary
-
SCROLL_POSITIONS =
# File 'lib/capybara/selenium/extensions/scroll.rb', line 48{ top: '0', bottom: 'arguments[0].scrollHeight', center: '(arguments[0].scrollHeight - arguments[0].clientHeight)/2' }.freeze
Instance Method Summary
Instance Method Details
#scroll_by(x, y)
[ GitHub ]# File 'lib/capybara/selenium/extensions/scroll.rb', line 6
def scroll_by(x, y) driver.execute_script <<~JS, self, x, y var el = arguments[0]; if (el.scrollBy){ el.scrollBy(arguments[1], arguments[2]); } else { el.scrollTop = el.scrollTop + arguments[2]; el.scrollLeft = el.scrollLeft + arguments[1]; } JS end
#scroll_element_to_location(element, location) (private)
[ GitHub ]# File 'lib/capybara/selenium/extensions/scroll.rb', line 32
def scroll_element_to_location(element, location) scroll_opts = case location when :top 'true' when :bottom 'false' when :center "{behavior: 'instant', block: 'center'}" else raise ArgumentError, "Invalid scroll_to location: #{location}" end driver.execute_script <<~JS, element arguments[0].scrollIntoView(#{scroll_opts}) JS end
#scroll_to(element, location, position = nil)
[ GitHub ]# File 'lib/capybara/selenium/extensions/scroll.rb', line 18
def scroll_to(element, location, position = nil) # location, element = element, nil if element.is_a? Symbol if element.is_a? Capybara::Selenium::Node scroll_element_to_location(element, location) elsif location.is_a? Symbol scroll_to_location(location) else scroll_to_coords(*position) end self end
#scroll_to_coords(x, y) (private)
[ GitHub ]# File 'lib/capybara/selenium/extensions/scroll.rb', line 64
def scroll_to_coords(x, y) driver.execute_script <<~JS, self, x, y if (arguments[0].scrollTo){ arguments[0].scrollTo(arguments[1], arguments[2]); } else { arguments[0].scrollTop = arguments[2]; arguments[0].scrollLeft = arguments[1]; } JS end
#scroll_to_location(location) (private)
[ GitHub ]# File 'lib/capybara/selenium/extensions/scroll.rb', line 54
def scroll_to_location(location) driver.execute_script <<~JS, self if (arguments[0].scrollTo){ arguments[0].scrollTo(0, #{SCROLL_POSITIONS[location]}); } else { arguments[0].scrollTop = #{SCROLL_POSITIONS[location]}; } JS end