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.
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);
2 Comments
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.
Comments
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);
}
get()along with the second and third url after first and second refresh.