4. How it works

In this section I will explain the purpose of all the functions in the code.

openTestSite() launches the Firefox browser and opens the test website:

1

2

3

publicvoidopenTestSite(){

driver.navigate().to("http://testing-ground.scraping.pro/login");

}

login() enters the provided username and password into the corresponding fields and submits the form. It does this by searching the form field elements on the page by their HTML Ids and by sending characters to those elements:

5. Run the program

To run the program, click on your project, and then select Run > Run as Java Application. The program will open the Firefox browser, and once the browser is closed the program execution is finished. To check the screenshot and text file, right click on the browser and click “refresh” button. Inside the project folder you will be able to see one text file and one png file.

That’s it. If you have any comments or questions feel free to ask! For a real-world exaple of scraping with WebDriver in Java look at this article.