Reputation: 33
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
And also the page has pagination
Upvotes: 0
Views: 1777
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
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