Am trying to scroll the page which is built using React JS.
The page is not scrolling even after using js.executeScript("scroll(0, 250);");
not working
and tried the method scroll until some element visibility.

- 12,047
- 2
- 12
- 31

- 9
- 1
-
2check this out https://stackoverflow.com/questions/12293158/page-scroll-up-or-down-in-selenium-webdriver-selenium-2-using-java It might help you – Akbar Feb 25 '19 at 06:16
-
@user966256 Update the question with the _url_ you are invoking through `get()` along with the second and third _url_ after first and second refresh. – undetected Selenium Feb 25 '19 at 09:31
3 Answers
Can you try this, I hope global variable window
is missed in your code
// scroll vertically
js.executeScript("window.scrollTo(0, 1000);")
// scroll horizontally
js.executeScript("window.scrollTo(1000, 0);")
//scroll to particular element
WebElement Element = driver.findElement(By.id("someID"));
js.executeScript("arguments[0].scrollIntoView();", Element);

- 4,389
- 2
- 18
- 21
-
No the same is worked for different sites but in this case after login dashboard is taking two auto refresh to load and then i need to scroll down. Not working – user966256 Feb 25 '19 at 07:32
-
You can use the below method that I have written to scroll to a particular element. You just need to pass Driver object.
// Method to scroll down to specific element
public static void scrollToElement(WebDriver driver) throws InterruptedException {
String key = "";
WebElement element = null;
JavascriptExecutor js = (JavascriptExecutor) driver;
element = driver.findElement(By.xpath(locator));
// This will scroll the page till the element is found
js.executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(2000);
}

- 12,582
- 6
- 26
- 49

- 188
- 8
-
No the same is worked for different sites but in this case after login dashboard is taking two auto refresh to load and then i need to scroll down. Not working – user966256 Feb 25 '19 at 07:35
-
-
@user966256 - have u used explicit or fluent waits for skipping 2 times page refresh time ? – Amit Jain Feb 25 '19 at 07:48
As u mentioned, page getting auto refreshed 2 times and then loading. There could be an issue because you trying to scroll the page after first auto refreshed. There shall be some micro second delay between these 2 auto refreshed so selenium is trying to scroll the page but before it could happen site is getting auto refreshed 2 time. Can I request you to have checkpoint before ur JavaScript scrolling method and do the debugging to ensure, it's actually working or not. If it does work then of course u need to perform any action after 2 auto refreshed happens.

- 1,936
- 2
- 8
- 20