0

I have a leader board element that I need to scroll down to view all players at the top of a web page using Selenium Java. Having spent the past 2 hrs googling I am only able to find answers by scrolling down a page that is not what I need.

I Have tried the following

        //click on leaderboard
    driver.findElement(By.xpath("//*[@id=\"root\"]/div/div/div[2]/div[1]/div[2]/div[1]/div/div")).click();

    //scroll
    WebElement scroll = driver.findElement(By.xpath("//*[@id=\"accordion-panel-1720\"]/div[2]/div"));
    Actions actions = new Actions(driver);
    actions.moveToElement(scroll).perform();

and

        WebElement scroll = driver.findElement(By.xpath("//*[@id=\"accordion-panel-1720\"]/div[2]/div"));
    Actions act = new Actions(scroll);
    act.sendKeys(Keys.PAGE_DOWN).build().perform(); //Page Down
    System.out.println("Scroll down perfomed");

2 Answers 2

1

So far, I've found two ways to do this for me: using Keys.ARROW_DOWN, Keys.PAGE_DOWN or executing a Javascript to scroll the element up/down.

JavascriptExecutor jsExec = (JavascriptExecutor) driver;
jsExec.executeScript("document.getElementById('id').scrollTop += 100");
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Javascript executor

For scroll down,

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,250)");

For scroll Up,

js.executeScript("window.scrollBy(0,250)");

you can also use to scroll until element is visible

js.executeScript("arguments[0].scrollIntoView(true);", element);

You can refer to this site

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.