Sometimes we would like to scroll webpage to particular WebElement or press Keyboard DOWN button to scroll the page. We can achieve scroll pages with below code snippets.
Scrolling Using javascript
Code :
WebElement ele = driver.findElement(By.id("test"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView()",ele);
Using Actions Class
package name : org.openqa.selenium.interactions.Actionsjava code :
Actions action=new Actions(driver);
action.sendKeys(Keys.DOWN).perform();
Without Using Actions Class
java code :
driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN);
Related Topics