Monday, October 14, 2013

Scroll Function in WebDriver

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.Actions

java 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





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.