I'm trying to test scrolling functionality by selenium webdriver. Same is working in Firefox but not in chrome driver. Here is basic code I'm using for scrolling.
Actions a = new Actions(driver);
WebElement el = driver.findElement(By.xpath("//*[@id='dsm-frame']"));
a.moveToElement(el).clickAndHold().moveByOffset(0, 1000000).release().perform();
Is there any specific reason that Action builder does not work in chrome? Kindly advise how it can be worked in Chrome driver.
Thanks
Selenium cannot directly scroll up or down with its methods. This is done with the Javascript Executor. DOM can interact with the elements with Javascript. Selenium runs the commands in Javascript with the execute_script() method.
Selenium can execute JavaScript commands with the help of the executeScript method. To scroll down vertically in a page we have to use the JavaScript command window. scrollBy. Then pass the pixel values to be traversed along the x and y axis for horizontal and vertical scroll respectively.
Selenium runs the commands in Javascript with the execute_script() method. For scrolling down to the bottom of the page, we have to pass (0, document. body. scrollHeight) as parameters to the method scrollBy().
You can use JavaScriptExecutor
for scrolling.
Scroll Down
((JavascriptExecutor)driver).executeScript("window.scrollTo(0,document.body.scrollHeight);");
Scroll Up
((JavascriptExecutor)driver).executeScript("window.scrollTo(0,0);");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With