Sunday, January 26, 2020

Scroll UP in Selenium Webdriver using JavaScriptExecutor

0 comments

If we change the Order of Execution in selenium we can make it UP scrolling



Check it out we can do this also

**********************CODE********************

package aveditor;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;



public class ScrollUP {
public static void main(String []args) throws Exception
{
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:\\Users\\oracle\\Music\\ChromeDriverPath\\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://automaticselenium.blogspot.com/p/example.html");
driver.manage().window().maximize(); //Maximize the Window after Opening the Links
// Actions Class
Actions actions=new Actions(driver);
JavascriptExecutor je=(JavascriptExecutor)driver;
WebElement scroll4=driver.findElement(By.xpath("//span[contains(text(),'UP TO THIS')]"));
je.executeScript("arguments[0].scrollIntoView()", scroll4);
System.out.println(scroll4.getText());

WebElement scroll3=driver.findElement(By.xpath("//span[contains(text(),'CHECKPOINT 3========>')]"));
je.executeScript("arguments[0].scrollIntoView()", scroll3);
Thread.sleep(5000);
System.out.println(scroll3.getText());
WebElement scroll2=driver.findElement(By.xpath("//span[contains(text(),'CHECKPOINT 2========>')]"));
je.executeScript("arguments[0].scrollIntoView()", scroll2);
Thread.sleep(5000);
System.out.println(scroll2.getText());
WebElement scroll=driver.findElement(By.xpath("//span[contains(text(),'CHECKPOINT 1========>')]"));
je.executeScript("arguments[0].scrollIntoView()", scroll);
System.out.println(scroll.getText());
}
}

No comments:

Post a Comment