Louis's answer works, but is not fully cross-browser compatible, as Internet Explorer does not support window.scrollY. I recommend using window.pageYOffset instead - this returns the same value, but is compatible with a cross browser.
Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY
Here is the code block above with the modified code:
JavascriptExecutor executor = (JavascriptExecutor) driver; Long value = (Long) executor.executeScript("return window.pageYOffset;");
In addition, the syntax for Ruby (what I use for the current position, assuming that before that the driver instance is available through the variable name, "driver"):
driver.execute_script('return window.pageYOffset;')
source share