
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to scroll down a webpage in selenium using Java?
We can scroll down a webpage in Selenium using Java. Selenium is unable to handle scrolling directly. It takes the help of the Javascript Executor to perform the scrolling action up to an element.
First of all, we have to locate the element up to which we have to scroll. Next, we shall use the Javascript Executor to run the Javascript commands. The method executeScript is used to run Javascript commands in Selenium. We shall take the help of the scrollIntoView method in Javascript and pass true as an argument to the method.
Syntax −
WebElement elm = driver.findElement(By.name("name")); ((JavascriptExecutor) driver) .executeScript("arguments[0].scrollIntoView(true);", elm);
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ScrollAction{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); //launch application driver.get ("https://www.tutorialspoint.com/about/about_careers.htm "); // identify element WebElement n=driver.findElement(By.xpath("//*[text()='Contact']")); // Javascript executor ((JavascriptExecutor)driver) .executeScript("arguments[0].scrollIntoView(true);", n); } }
Output
- Related Articles
- How to scroll down using Selenium WebDriver with Java?
- Is it possible to scroll down in a webpage using Selenium Webdriver programmed on Python?
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to scroll up/down a page using Actions class in Selenium?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to detect Scroll Up & Scroll down in Android ListView using Kotlin?
- How to get screenshot of full webpage using Selenium and Java?
- How to refresh a webpage using Python Selenium Webdriver?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to find Elements in a Webpage using JavaScript in Selenium?
- How to detect scroll up and scroll down in android listView?
- How to loop through a menu list on a webpage using Selenium?
- How to scroll to element with Selenium WebDriver using C#?
- How do you check scroll position using selenium?

Advertisements