Friday, 19 February 2016

How to scroll to element in Selenium Webdriver

When automating the iOS applications running on iPad or iPhone in Safari, you encounter exceptions like element is not visible. But the same code works fine on other browsers like chrome and firefox.
So what is causing the issue in safari?

To fix this issue, you need to scroll to element and then work on that element.
Below method will accept the element and scroll to it.

public void scrollToElement(WebElement element){
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",element)
        ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-100)")

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at


  1. hey..u hv good knowledge on selenium..but i wonder y ur blog is not that much popular :P

    1. Thanks mate! I am trying to increase the ranking of my blog! I hope it happens soon!

  2. You are doing a good job. These questions are mostly asked in the interviews. Keep going.


Buy Best Selenium Books