How to perform Scroll into view in Selenium WebDriver:
In Selenium we don't have inbuilt methods to perform scroll into view operations.
So,with the help of JavaScriptExecutor interface we can perform Scroll into view operations in Selenium WebDriver
Example:
package com.rameshsoft.rameshselenium;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ScrollIntoWebPageDemo{
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ramesh\\Desktop\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/complete_examples.html");
JavascriptExecutor js = (JavascriptExecutor) driver;
//find any webelement which will be appear after scrolling down
WebElement element = driver.findElement(By.xpath(".//*[@id='mCSB_1_container']/p[8]/img"));
js.executeScript("arguments[0].scrollIntoView(true);",element);
}
}
No comments:
Post a Comment