How to scroll to a particular element on a webpage using selenium ruby webdriver?

0 votes
How to scroll to a particular element on a webpage using selenium ruby webdriver?
Aug 23 in Selenium by Disha
20 views

1 answer to this question.

0 votes

Hey Disha, following piece of code worked for me to scroll to a web element:

def scroll_to_element_action(element, locator=nil)
    script = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + "var elementTop = arguments[0].getBoundingClientRect().top;" + "window.scrollBy(0, elementTop-(viewPortHeight/2));"
    element = element.nil? ? find(locator) : element
    execute_script(script, element)
  end
answered Aug 26 by Abha
• 23,030 points
can't understand the code...can someone explain it?

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

How to mouse hover on a web element using Selenium WebDriver?

Hello Nitin, to automate mouse hovering over ...READ MORE

answered May 7 in Selenium by Anvi
• 12,860 points
144 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
593 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
901 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
581 views
0 votes
1 answer
0 votes
1 answer