Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll down using Selenium WebDriver with Java

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

like image 629
Er KK Chopra Avatar asked Apr 22 '13 05:04

Er KK Chopra


People also ask

How can you scroll the page down in Selenium?

Hence, to scroll up or down with Selenium, a JavaScriptExecutor is a must. The scrollBy() method involves two parameters, x, and y, that represent the horizontal and vertical pixel values, respectively.

How do you scroll down to the bottom of a page in Selenium Java?

Selenium runs the commands in Javascript with the execute_script() method. For scrolling down to the bottom of the page, we have to pass (0, document. body. scrollHeight) as parameters to the method scrollBy().


1 Answers

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

JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,450)", "");
like image 61
HemChe Avatar answered Oct 20 '22 08:10

HemChe