Hi Community members,
Have you ever found it difficult to manage the act of scrolling on a table or web page when a component has several scrolls?
The AG Grid Table is a featured example of the situation that we mentioned above.
The table has two distinct scroll bars, such as the horizontal and vertical ones.
We must accurately define the desired scroll bars to accomplish scrolling precisely.
For example, with this page https://ag-grid.com/example/
We have the class names of scroll bars below
Vertical Bar:
.ag-body-vertical-scroll-viewport
Horizontal bar:
.ag-body-horizontal-scroll-viewport
How can we get those names precisely? Let us show you the tips below:
Pause the web page in 3 seconds to capture the scroll bar by using the command
Note: This approach suits hidden scroll bars
setTimeout(() => {debugger}, 3000)
- Open the DOM
- Select the “Console” tab
- Type the command: setTimeout(() => {debugger}, 3000)
- Enable the Scroll bar
Then, we can inspect the scroll bar to obtain the exact name while the website is paused for debugging.
Now, we go through the typical actions we take while dealing with scrolling bars:
Scenario 1: Scroll from Left to Right
def scrollHorizontalBy = 2000; // An estimated number that
indicates where the element is that we need to scroll to.
def horizontalScrollbar = WebUIAbstractKeyword.findWebElement(
findTestObject('Object Repository/HorizontalBar'), 30);
WebUI.executeJavaScript('arguments[0].scrollBy(
{ left: arguments[1], behavior: "smooth" })',
[horizontalScrollbar, scrollHorizontalBy]);
Scenario 2: Scroll from Right to Left
def scrollHorizontalBy = -2000; // An estimated number that
indicates where the element is that we need to scroll to.
def horizontalScrollbar = WebUIAbstractKeyword.findWebElement(
findTestObject('Object Repository/HorizontalBar'), 30);
WebUI.executeJavaScript('arguments[0].scrollBy(
{ left: arguments[1], behavior: "smooth" })',
[horizontalScrollbar, scrollHorizontalBy]);
Scenario 3: Vertical Scrolling
def scrollVerticalBy = 500; // An estimated number that
indicates where the element is that we need to scroll to.
def verticalScrollbar = WebUIAbstractKeyword.findWebElement(
findTestObject('Vertical Scrollbar'), 0);
WebUI.executeJavascript('arguments[0].scrollBy(
{ top: arguments[1], behavior: "smooth" })',
[verticalScrollbar, scrollVerticalBy]);
We hope you find the information above interesting. If so, kindly leave your thoughts on this article, and we will arrange advanced sharing during the upcoming sessions that will address the scroll bars on the AG Grid Table.
Moreover, please feel free to share with us more scrolling situations that you have used in your projects. You can also share with us any recommendations you have for using scrolling bars to improve the community’s experience with automated testing.
Reference
https://dev.azure.com/linhnguyen0979/_git/KShare_AGGridTable_ScrollingBars
If you find this article helpful, then don’t forget to leave us a like or !