Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Saturday, 7 March 2015

Scrolling using Selenium WebDriver


Selenium Webdriver doesn't provide an inbuilt method for page scrolling
By using JavaScript interface we can scroll in Page(Horizontal,Vertical).
We need to import this packege import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ScrollDemo {
 public static void main(String[] args) throws Exception {
   WebDriver driver=new FirefoxDriver();
   driver.manage().window().maximize();
    driver.get("http://facebook.com");
   Thread.sleep(5000);
 JavascriptExecutor jse = (JavascriptExecutor)driver;
  jse.executeScript("scroll(0, 1500)"); //y value  can be altered
  Thread.sleep(5000);
   JavascriptExecutor jse1 = (JavascriptExecutor)driver;
  jse1.executeScript("scroll(250, 0)"); //x value can be altered
 }}


Output:First it will scroll down(Y axis) and after 5 seconds it will scroll up(X axis).

0 comments:

Post a Comment

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: