0

Is there any other way to scroll up/down in a web page without using JavaScriptExecutor ?

3 Answers 3

1

You can try the PageUp and PageDown keys as an alternate:

Syntax: driver.findElement(By.xpath("xpath")).sendKeys(Keys.PAGE_DOWN)

Sign up to request clarification or add additional context in comments.

Comments

0

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

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.