We can scroll the web pages with the help of JavascriptExecutor interface and scrollBy method. In scrollBy method we pass the x-axis pixels and y-axis pixels.
window.scollBy(x-pixels,y-pixels);
or
window.scollBy(width,height);
JavascriptExecutor executor = (JavascriptExecutor)driver;
//scroll down
executor.executeScript("window.scrollBy(0,1000)");
//scroll Up
executor.executeScript("scroll(0,-500)");
In some case, if I need to scoll down the page and click on any link on the page then how I know how much page should be scroll for clicking on the link.
In this case we need the below code for clicking to this link.
WebElement element=driver.findElement(By.partialLinkText("November"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].scrollIntoView(true);",element);
element.click();
No comments:
Post a Comment