4

I'm using Selenium with Java and ChromeDriver to run few scripts on a website. I want to scroll the driver or the page to an specific element located on the page. It might be visible. I understand that with a JavascripExecutor it's possible, but so far the way I'm doing it I can only scroll certain "spaces". Here is what I have:

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

1 Answer 1

4

If you want to scroll to specific element, you should try using scrollIntoView(true) as below :-

//Find that specific element first 
WebElement element = driver.findElement(..);

//Now scroll to this element 
jse.executeScript("arguments[0].scrollIntoView(true);", element);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much this is what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.