0

enter image description here

I have used the codes like

For Scroll Down:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
jse.executeScript("scroll(0, 250);");

For Scroll Up:

jse.executeScript("window.scrollBy(0,-250)", "");
OR,
jse.executeScript("scroll(0, -250);");

Its not throwing any error message. Test case is passed.

Please don't mark below link for reference because i have already verified and try to implemented that was not working so please give different solutions.

Page scroll up or down in Selenium WebDriver (Selenium 2) using java

tsr_qa
  • 623
  • 3
  • 8
  • 27

3 Answers3

0
WebElement word1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("abc")));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", word1);

In above code write the element which is placed at the bottom of page or at the top of page.According to which it will perform scroll up or down.

Sneha Shinde
  • 356
  • 1
  • 7
0

Can you try once using actions

Actions actions = new Actions(driver);
// Page Down
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
// Page Up
actions.keyDown(Keys.CONTROL).sendKeys(Keys.UP).perform();
Y-B Cause
  • 1,193
  • 15
  • 38
0

I have discovered a handy tricky hacky stuff over the years (I've been using Selenium for 150 years).

Whenever you're unable to scroll up a form, just send keys into an input on the top of the page. The driver will find it and will automagically scroll up the page to perform the action.

Whenever I think about this trick, I realize being an old man isn't that bad.

Good luck you fresh sailor, see you on the shores of Selenia.

Y-B Cause
  • 1,193
  • 15
  • 38