This post I am going to share the basics of setting up and running a simple but working Selenium WebDriver example. The hypothetical requirement this example is trying to accomplish is following:
Print out all addresses on rightmove.co.uk for 3 bedroom properties for sale in Reading under £175K
Requirements looks simple. Lets get started.
Print out all addresses on rightmove.co.uk for 3 bedroom properties for sale in Reading under £175K
Requirements looks simple. Lets get started.
Setup Java project using Maven
Assuming you have maven installed on your system, run the following command to setup a generic java project.
Update pom.xml to
- Include selenium-firefox-driver and selenium-support dependencies.
- Generate a executable jar file. This example pom.xml assumes that your main class would be named PropertyAddressFinder.
Selenium
Import this maven project in your favourite IDE and add PropertyAddressFinder class. Java code below should be self explanatory. It uses Selenium FirefoxDriver to open the website and search for properties .
Run the Project
Now that we have the bits and pieces in place, we can let maven do the magic and make us a executable jar file, refer pom.xml's build section above to see how we achieve this. Executing the jar file via command line will open a firefox browser and print out whatever properties it finds.
Conclusion
Above blog demonstrates a very basic usage of selenium webdriver to automate web based tasks that cannot be otherwise achieved via well known api's.
No comments:
Post a Comment