0

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.

2
  • 2
    check this out stackoverflow.com/questions/12293158/… It might help you Commented Feb 25, 2019 at 6: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. Commented Feb 25, 2019 at 9:31

3 Answers 3

0

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);
Sign up to request clarification or add additional context in comments.

2 Comments

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
do you solve your problem? I have the same problem.
0

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

0

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

3 Comments

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
I tried with wait, sleep, and everything still facing issue
@user966256 - have u used explicit or fluent waits for skipping 2 times page refresh time ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.