15

I want to scroll down my web page and i m using this code to scroll page but it is not working

public ViewBasketSentToMePageObject viewSlideShare() throws InterruptedException {

    Thread.sleep(500l);

    Actions action1 =new Actions(getDriver());
    action1.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0030')).build().perform();

    List<WebElement> function = getDriver().findElements(By.xpath("//a [@ng-click='onItemClick()']"));
    function.get(13).findElement(By.xpath("//img [@ng-src='resources/images/slideshare-icon-small.png']")).click();

    return getFactory().create(ViewBasketSentToMePageObject.class);
}

Looking for help

Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35
Er KK Chopra
  • 1,834
  • 8
  • 31
  • 55
  • 2
    Your problem earlier Solved Here: http://stackoverflow.com/questions/12293158/page-scroll-up-or-down-in-webdriver-selenium-2-using-java – maximkou Apr 22 '13 at 06:12

4 Answers4

25

Try using simple java script below and you can scroll the page.

JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,450)", "");
HemChe
  • 2,249
  • 1
  • 21
  • 33
6

For scroll down:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 250);");

or, you can do as follows:

jse.executeScript("window.scrollBy(0,250)", "");
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
1

Scroll until find the WebElement

Try this:

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", your_WebElement);
Chathura
  • 31
  • 1
  • 5
0
WebElement element = driver.findElement(By.xpath("//input [@id='giveid']"));

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);

Use this. This will help you to scroll down at the particular element. I had tested on my website even. It is working fine.

SuRa
  • 1,053
  • 9
  • 13