Is there any other way to scroll up/down in a web page without using JavaScriptExecutor ?
3 Answers
u can scroll down by using:
driver.findElement(By.xpath("xpath")).sendKeys(Keys.PAGE_DOWN)
but this will scroll down only once.
but if u want to move to that elemnt, use the below code:
WebElement scroll = driver.findElement(By.cssSelector("ur selector"));//u can use By.xpath or By.id here
Actions actions = new Actions(driver);
actions.moveToElement(scroll);
actions.perform();
this will take u to the element by scrolling.
Comments
Please try below code as per your requirement:
//Scroll to element using Keys
Actions action = new Actions(dr);
action.sendKeys(Keys.PAGE_DOWN);
Thread.sleep(5000);
action.click(driver.findElement(By.partialLinkText("XYZ"))).perform();
//For scrolling on the page
for (int second = 0;; second++) {
if(second >=60){
break;
}
driver.executeScript("window.scrollBy(0,200)", "");
Thread.sleep(1000);
}
//Scroll bottom of the Page:
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();