private void isScrolledTo ( String action , String expected ) { WebElement webElement = getWebElement ( ) ; long elementPosition = webElement . getLocation ( ) . getY ( ) ; JavascriptExecutor js = ( JavascriptExecutor ) driver ; int scrollHeight = ( ( Number ) js . executeScript ( "return document.documentElement.scrollTop || document.body.scrollTop;" ) ) . intValue ( ) ; int viewportHeight = ( ( Number ) js . executeScript ( "return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" ) ) . intValue ( ) ; if ( elementPosition < scrollHeight || elementPosition > viewportHeight + scrollHeight ) { reporter . fail ( action , expected , prettyOutputStart ( ) + " was scrolled to, but is not within the current viewport" ) ; } else { reporter . pass ( action , expected , prettyOutputStart ( ) + " is properly scrolled to and within the current viewport" ) ; } }
Determines if the element scrolled towards is now currently displayed on the screen