liki
liki

Reputation: 33

How to scroll down a specific div of page having pagination using selenium webdriver

I am trying to scroll down page and get the last element of that section/div. i have executed the code:


Coordinates coordinate = ((Locatable)element).getCoordinates();
    coordinate.inViewPort();

and also tried with

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 250)");

But it is scrolling the entire page instead of scrolling the specific section enter image description here

And also the page has pagination

Upvotes: 0

Views: 1777

Answers (2)

Siva
Siva

Reputation: 1149

What you have tried will scroll the window scroll bar, try something like below

JavascriptExecutor je = (JavascriptExecutor) dr;  
je.executeScript("arguments[0].scrollIntoView(true);",dr.findElement(By...));

Specify the locator of the element which you are trying to find by scrolling down.

arguments[0]

Edit:

JavascriptExecutor je = (JavascriptExecutor) dr;  
je.executeScript("arguments[0].scrollTop(arguments[0].scrollHeight);",dr.findElement(By...));

Upvotes: 0

Cosmin
Cosmin

Reputation: 2394

First you need to find the element you're trying to scroll to:

WebElement element = driver.findElement(By.xpath("xpath_here")); //or anything else used to identify the element

Afterwards, you can execute JS using JavascriptExecutor to bring the element into view using scrollIntoView() :

((JavaScriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", element);

Upvotes: 2

Related Questions