- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to scroll down using Selenium WebDriver with Java?
We can scroll down with Selenium. 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 to. 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.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class ScrollAction{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/about/about_careers.htm "); driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // 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 the Page up or down in Selenium WebDriver using java?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to scroll to element with Selenium WebDriver using C#?
- How to scroll down a webpage in selenium using Java?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to scroll down the page till page end in the Selenium WebDriver?
- Is it possible to scroll down in a webpage using Selenium Webdriver programmed on Python?
- How to scroll up/down a page using Actions class in Selenium?
- How to type in textbox using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Java?
- How to handle authentication popup with Selenium WebDriver using Java?
- How can I scroll a web page using selenium webdriver in python?
- Switch tabs using Selenium WebDriver with Java.
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to select checkboxes using selenium java webdriver?

Advertisements