-->

9/19/2019

Write a Java Program to demonstrate Scroll up/ Scroll down.

All the lines of codes are easily relatable as we have discussed in our previous example.
However, in this program, we have included our JavascriptExecutor js which will do the scrolling. If you see the last line of the code, we have passed window.scrollBy(arg1,arg2).
If we want to scroll up then pass some value in arg1 if you want to scroll down then pass some value in arg2.

1package Codes;
2 
3import java.util.concurrent.TimeUnit;
4 
5import org.openqa.selenium.By;
6import org.openqa.selenium.JavascriptExecutor;
7import org.openqa.selenium.Keys;
8import org.openqa.selenium.WebDriver;
9import org.openqa.selenium.WebElement;
10import org.openqa.selenium.chrome.ChromeDriver;
11 
12public class ScrollDown {
13 
14          public static void main(String[] args) {
15                   // TODO Auto-generated method stub
16                   System.setProperty("webdriver.chrome.driver""C:\\webdriver\\chromedriver.exe");
17                   WebDriver driver = new ChromeDriver();
18                   JavascriptExecutor js = (JavascriptExecutor) driver;
19                   driver.manage().window().maximize();
20                   driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
21                   driver.get("https://www.google.com");
22                   WebElement element = driver.findElement(By.name("q"));
23                   element.sendKeys("SoftwareTestingHelp");
24                   element.sendKeys(Keys.ENTER);
25                    js.executeScript("window.scrollBy(0,1000)");
26 
27}
28 
29}
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post