In Leapwork, many building blocks have a “Scroll to Find” and "Scroll into view" built-in option which can be used to scroll on an application.
Run web JavaScript building block also has the capability to perform a scroll action on the screen.
Vertical Scroll
To perform a vertical scroll, there are 4 ways:
Method 1. Scroll to find
When a value other than “None” is selected, the building block will use scrolling when searching for the web element. This can be useful when searching for scrollable content such as web pages where elements are loaded asynchronously, e.g. using infinity scroll.
Max repeats -The maximum number of times to perform a scroll before giving up searching for the web element.
Amount - The amount of scrolling that will be performed on each scroll repeat.
Delay (sec) -The delay in seconds between each of the scroll amounts.
Method 2. Scroll into view
When this option is checked, any found web element is automatically scrolled into view.
Method 3. Run web JavaScript block to scroll down
To scroll down, we use window.scrollBy(x, y); and specify the pixel on the y axis as per the user's requirement.
Syntax:
window.scrollBy(xnum, ynum)
xnum Number Required. How many pixels to scroll by, along the x-axis (horizontal). Positive values will scroll to the right, while negative values will scroll to the left
ynum Number Required. How many pixels to scroll by, along the y-axis (vertical). Positive values will scroll down, while negative values scroll up
Note: The pixel on the x-axis should be 0 and the pixel value on the y-axis should be positive in order to scroll down by the pixels.
In the above scenario, it will scroll down by 1000 pixels since 1000 is given as the y-axis value.
Method 4. Run web JavaScript block to scroll up
To scroll up, we use window.scrollBy(x, y); and specify the pixel on the y axis as per the user's requirement.
Note: The pixel on the x-axis should be 0 and the pixel value on the y-axis should be negative in order to scroll up by the pixels.
In the above scenario, it will scroll up by 1000 pixels since -1000 is given as the y-axis value
Horizontal Scroll:
Method 1. Run web JavaScript block to scroll right
To scroll right, we use window.scrollBy(x, y); and specify the pixel on the x-axis as per the user's requirement.
Note: The pixel on the x-axis should be positive and the pixel value on the y-axis should be 0 in order to scroll right by the pixels.
In the above scenario, it will scroll right by 1000 pixels since 1000 is given as the x-axis value
Method 2. Run web JavaScript block to scroll left
To scroll left, we use window.scrollBy(x, y); and specify the pixel on the x-axis as per the user's requirement.
Note: The pixel on the x-axis should be negative and the pixel value on the y-axis should be 0 in order to scroll left by the pixels.
In the above scenario, it will scroll left by 1000 pixels since -1000 is given as the x-axis value.
For any clarification, please contact our Priority Support.
Comments
0 comments
Please sign in to leave a comment.