I am working for a website automation testing. I need to scroll many times. How to find a Scroll bars`s Xpath in a browser ?
ScrollBars are operating system elements and cannot be driven by Selenium or WebDriver like other elements.
Possible ways to scroll with Selenium are:
This scrolls down 250 pixels for more idea's check this question: https://stackoverflow.com/questions/12293158/page-scroll-up-or-down-in-selenium-webdriver-selenium-2-using-java
Scroll to a known element with Actions
WebElement element = driver.findElement(By.id("my-id")); Actions actions = new Actions(driver); actions.moveToElement(element); actions.perform();
This scrolls to the element, for more idea's for scrolling to elements check this question: https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium
I think the Action way is preferred, but it needs an element.
Trigger the real scrollbar
If for some reason you really need to use the scrollbar like a real user would, because you have some action/event/trigger (I cannot come up with a good example). Then you could have a look at automation frameworks that can influence the operating system for example like: Sikuli or AutoIt
This should be your last resort though, I would suspect the
window.scrollBy() to fire most events you would like to test.
As noted by others, scrollbars are part of the browser and not the HTML document.
But you can access the scrollbars by using visual web testing tools like Kantu or Sikuli. The Kantu Browser is is a wrapper for Chromium and thus has access to the scrollbar via its SCROLL page up/down command (pretty obvious command name).
Sikuli even has commands for things like scroll-wheel simulation (wheel(target, WHEEL_UP | WHEEL_DOWN, steps).
This code is for scrolling to the full height of the page. It will scroll down to the end of the page.
This is for scrolling in upward direction.
String jsCode2 = "window.scrollBy(0, -1000)"; je.executeScript(jsCode2);