Marcus Marcus - 1 year ago 124
C# Question

How to scroll down a sub-section in Selenium (C#)?

I am UI-testing a web page with a grid on it, using Selenium Webdriver in C#.

The grid has its own scroll bar and I would like to scroll down to the bottom of the grid to check a certain result has appeared when I add it through a modal form (the UI test is currently failing as it can't see the result until I scroll down).

How do I target the scroll bar on the grid as opposed to the normal scroll bar on the main webpage? This is the HTML of my grid's scroll bar:

<div class="ScrollbarLayout_face ScrollbarLayout_faceVertical public_Scrollbar_face" style="height: 367.38px; transform: translate3d(0px, 148.535px, 0px); backface-visibility: hidden;"></div>

I was thinking of using the below code, but I can't think how to target an element at the bottom of the grid to scroll to?

WebElement element = driver.findElement("my-id"));
Actions actions = new Actions(driver);

Answer Source

First set focus to any object of grid by using any event


Then add below two lines:

Actions actions = new Actions(driver);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download