Sunday, March 15, 2015

Handling Scrollbar in Selenium webdriver






In this Tutorial we are going to see how to handle Scroll bar in the Web browser.

In this Example .

  • Navigating to "http://automationplace.blogspot.in/" 
  •  Scroll down the Scrollbar to down and Click on "OlderPost" link
  • Assert the Actual and Expected URL's 

The below Code is used to Scroll the Scrollbar down



EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver);
eventFiringWebDriver.executeScript("scroll(0,4000)",args);



Source code:



import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;



public class testscroll {
      
      

       public static void main(String[] args) throws InterruptedException  {
              // TODO Auto-generated method stub
             
              WebDriver webDriver = new FirefoxDriver();

              webDriver.get("http://automationplace.blogspot.in/");

              webDriver.manage().window().maximize();

              EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver);
              eventFiringWebDriver.executeScript("scroll(0,4000)",args);
             
              webDriver.findElement(By.id("Blog1_blog-pager-older-link")).click();
              Thread.sleep(8000);
              String actual="http://automationplace.blogspot.in/search?updated-max=2015-02-16T18:02:00-08:00&max-results=7";
              Thread.sleep(5000);
              String expectedurl=webDriver.getCurrentUrl();
              Assert.assertEquals(expectedurl, actual);
              System.out.println("result is correct");

             
             
       }
}
             
 

 
 Thanks,
Hope you like this post. 




 

1 comment:

  1. Such an excellent and interesting information in your blog, it is awesome to read and do post like this with more informations.  Salesforce Training Australia    

    ReplyDelete