Friday 7 June 2013

Scroll down method in WebDriver

Here i am adding simple code for Scroll down method.we can scroll down and up methods in a 3 ways....

Using JavaScriptExecutor:

  JavascriptExecutor jsx = (JavascriptExecutor)driver;

  jsx.executeScript("window.scrollBy(0,450)", "");

 

 Using Actions Class

Actions action=new Actions(driver);
       action.sendKeys(Keys.DOWN).perform();
       action.sendKeys(Keys.DOWN).perform();
       action.sendKeys(Keys.DOWN).perform();
       action.sendKeys(Keys.DOWN).perform();
     
   {OR}

Actions action=new Actions(driver);
                  action.keyDown(Keys.CONTROL).sendKeys(Keys.PAGE_DOWN).perform();

   {OR}

With out Using Actions Class

 for(int i=0;i<20;i++)
                    {
                             driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN);
                    }



2 comments:

  1. Your javascript code solved it . Thanks !!!

    ReplyDelete
  2. Hi Sivaprasad Kandula,

    I think these methods would not work if there are multiple scroll-bars and each residing a in a different div sections which are not in an iframe.
    Do you have any suggestions for those cases?

    Thanks,
    dl

    ReplyDelete