Selenium WebDriver- Scrolling a web page
In this section, you will learn how to scroll down or up in order to display additional information present on the web page.
Let us consider a test case in which we will automate the following scenarios:
Step1. Launch Eclipse IDE and open the existing test suite "Demo_Test" which we have created in earlier sessions of this tutorial.
Step2. Right click on the "src" folder and create a new Class File from New >Class.
Give your Class name as "Scroll_Test" and click on "Finish" button.
Step3. Let's get to the coding ground.
Here is the sample code to set system property for Gecko driver:
Here is the sample code to initialize gecko driver using DesiredCapabilities class.
Combining both of the above code blocks, we will get the code snippet to launch Firefox browser.
Here is the sample code to navigate to the desired URL:
The complete code till now will look something like this:
Step4. To automate our third test scenario, we need to write the code which will scroll down the webpage in order to show the Java Technology section present on the JavaTpoint website.
Thus, our final test script will look something like this:
Upon execution, the above test script will launch the Firefox browser and automate all the test scenarios.