Skip to content

Instantly share code, notes, and snippets.

@henrrich
Created July 13, 2016 12:20
Show Gist options
  • Save henrrich/7a04f46558a0d4c6755d37e4018a684d to your computer and use it in GitHub Desktop.
Save henrrich/7a04f46558a0d4c6755d37e4018a684d to your computer and use it in GitHub Desktop.
Implementation of webdriver inViewPort method in javascript.
/**
* This method is a replacement to the inViewPort method from selenium webdriver API.
* It uses javascript to scroll.
* For parameter details, check the link below:
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView">Element.scrollIntoView()</a>
*/
public void inViewPort(boolean alignToTop, WebElement element) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(" + alignToTop + ")", element);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment