I want to get the position of an element relative to the browser\'s viewport (the viewport in which the page is displayed, not the whole page). How can this be done in JavaS
This way is also applicable for calling in JAVA:
Object bound = driver.executeScript("var bounding = arguments[0].getBoundingClientRect();" +
"return bounding.top >= 0 && " +
" bounding.left >= 0 && " +
" bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && " +
" bounding.right <= (window.innerWidth || document.documentElement.clientWidth)",
element);
boolean isElementInView = ((Boolean)bound).booleanValue(); //returns true if element in viewport