Scrolling down to get an element using Selenium
In test automation, this becomes important when you want to check that all the expected elements are displayed on the page. For example, while we certainly want to click on an element, we might not be able to see the element because we need to scroll up or down the page.
As a newbie, I’m struggling to find a suitable and functional script for my project. However, there are numerous ways to implement scroll-down functionality. Let’s explore some of them :
This is my first time attempting to use the script mentioned below. I am using the SendKeys
function provided by Selenium. However, it isn’t working for me because I intend to implement the script for an Android app using Appium. The script will work perfectly if used for a webpage.
Next trial, I am utilizing the driver.FindElement
command with the selected XPath selector. The last line involves the JavaScriptExecuteScript, where I instruct my code to scroll to the element until it is found.
However, repeatedly, it doesn’t work with Appium. I tried the script on the webpage, and it worked there.
Finally, I have found a suitable script that effectively scrolls down to locate an element. The following script will continuously navigate to an element until the textContains function identifies the intended text and makes it visible. Here is the script I mentioned :
That’s a glimpse of the lessons I can share. Thank you, and don’t forget to give a clap and subscribe.