How to scroll down particular Div element in a web page?

743 views
Skip to first unread message

Minni

unread,
Nov 15, 2019, 3:30:36 AM11/15/19
to Selenium Users
Hello Friends,

I already searched for the solution for the below problem but I didn't find any solution.  I found similar posts and i tried those solutions but nothing is worked. That's why I am posting here.

I am using selenium webdriver with Java on firefox browser. I am facing an issue with scrolling down "Div" element on the webpage.  I was not able to scroll down the Div element. 
This Div element is only enabled when we place the mouse at that point or when move-in /out from that place.

Div element object properties are given below.

<div class="slimScrollBar" style="background: rgb(0, 0, 0) none repeat scroll 0% 0%; width: 7px; position: absolute; top: 0px; opacity: 0.4; display: none; border-radius: 7px; z-index: 99; right: 1px; height: 30px;"></div>

I tried javascript execution, locators , Keys down etc etc..but nothing didnt work.

Workarounds:
1).

WebElement ddl_scrollDown = driver.findElement(By.cssSelector("div.slimScrollBar")); 

Coordinates cor=((Locatable)ddl_scrollDown).getCoordinates();

cor.inViewPort();


2).

WebElement ddl_scrollDown = driver.findElement(By.cssSelector("div.slimScrollBar"));                                                        

ddl_scrollDown.sendKeys(Keys.PAGE_DOWN);


3).

WebElement ddl_scrollDown = driver.findElement(By.cssSelector("div.slimScrollBar"));                                                        (JavascriptExecutor)driver).executeScript("arguments[0].click();",ddl_scrollDown);


4).

String st = "div.slimScrollBar";

String s = String.format("var topPos = document.querySelector(\""+st+"\"); topPos.scrollIntoView(false); ");

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript(s);


And I attached a screenshot for reference.



I would really appreciate it if anyone provides the solution.

Thank you,
Minni
scrolldown.png

Abdessalam Aadel

unread,
Nov 18, 2019, 4:49:35 PM11/18/19
to Selenium Users

Hi
You should use scrollIntoView()
JavascriptExecutor js = (JavascriptExecutor) driver;
js.ExecuteScript("arguments[0].scrollIntoView();", element);

In the above statement element is the exact element where we need to scroll
or :
js.ExecuteScript("javascript:window.scrollBy(0,100)"); //Scroll down vertically by 100 pixels
or you should use Actions class to perform scrolling to element
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Perform();
Good luck ...

Minni

unread,
Dec 3, 2019, 11:16:43 AM12/3/19
to Selenium Users
Hi Aadel,

Thank you so much for your reply.

I tried ScrollIntoView as well (see my 4th workaround). But it didn't work. And i also i tried actions but its getting error.
"org.openqa.selenium.WebDriverException: Unable to convert: {actions=[org.openqa.selenium.interactions.Sequence@5ff2b8ca]}"

Please let me know if you have any other fix for this?

Thanks
Minni
Reply all
Reply to author
Forward
0 new messages