How to Scroll in Selenium?
Answer: One cannot scroll in selenium, for that you have to use JavaScriptExecutor class:
1.Using scrollBy method in JavaScriptExecutor:
main(){
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Krunal.Kadu\\Desktop\\Krunal\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://practice.automationtesting.in/");
JavaScriptExecutor js = (driver)JavaScriptExecutor; // cast driver to jsexecutor type
js.executeScript("arguements[0].scrollBy(0,250);",driver.findElement(By.xpath("//div/input[1]")));
}
2. Using scrollIntoViewMethod in JavaScriptExecutor:
js.executeScript("arguements[0].scrollIntoView(true);",driver.findElement(By.xpath("//div/input[1]")));
Comments
Post a Comment