Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created January 30, 2024 10:17
Show Gist options
  • Save SarahElson/4597cc0d6ab2844d26a9c31221f4d281 to your computer and use it in GitHub Desktop.
Save SarahElson/4597cc0d6ab2844d26a9c31221f4d281 to your computer and use it in GitHub Desktop.
How To Scroll Down in Selenium WebDriver
package test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
public class ScrollDownByElementVisibility extends BaseTest{
@Test
public void testScrollDownByElementVisibility()
{
//launch the website
driver.get("https://www.lambdatest.com/selenium-playground/");
//specify the WebElement till which the page has to be scrolled
WebElement element = driver.findElement(By.linkText("Espresso Testing"));
//get the height of the web page and scroll to the end
js.executeScript("arguments[0].scrollIntoView();", element);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment