1

I have this part of the code in my Selenium Webdriver test in java. I use this javascript code to scroll to a particular value i in the page.

((JavascriptExecutor) driver).executeScript("scroll(0,"+i+");");

scroll(0,y) doesn't return a value. Is there any way to know if this script has been executed ?

Govind Singh
  • 15,282
  • 14
  • 72
  • 106
anirudh_raja
  • 369
  • 2
  • 9
  • 20

1 Answers1

2

Did you try getting a return value from the script which then you can handle from Selenium itself? Try using:

if(window.pageYOffset!= undefined){
  return [pageXOffset, pageYOffset];
}

This will return the offsets for you after the scroll. You can then assert if this scroll position is the one you want or not.

Further detail on this approach can be found here:

Getting the return value of Javascript code in Selenium

How to get scrollbar position with Javascript?

Community
  • 1
  • 1
magicode118
  • 1,444
  • 2
  • 17
  • 26