Getting started with Selenium WebDriver in Java on Windows

Note My personal opinion is, that Java is the most popular programming language in the Selenium project.

IDE The official one: The 5 Minute Getting Started Guide Note: Here you find an example with HtmlUnitDriver. I experienced too often, that HtmlUnitDriver wasn’t working even with correct Selenium code, so I recommand not using it at all. IDE, without Maven This approach is, regarding Java, the most “back-to-the-roots” one but takes the most time. If you like to start with Selenium while refreshing you Java knowledge take this one.

All guides are different ways for the same goal: get your first Selenium program run.

Some backgrounds to Java This paragraph is only a little refreshment for your aged Java knowledge. If you never had Java knowledge, you should go for a tutorial. If you haven’t done yet, download the Java JDK from the download page the most actual Java Platform The Compiler is necessary, because you have to compile the file of your source-code yourname .java to become an executable file. The program then can be executed by java yourname in your Command Prompt you navigated in the directory, where the yourname .class resides

Firefox To run your first Selenium program on Firefox, you need to download Firefox here and install it.

Selenium Setup For working with Selenium, you need to include the right Selenium library. There are plenty of libraries available in the Selenium project, which probably is confusing in the beginning: download page . A good choice is the latest version of selenium-server-standalone-x.y.z.jar y and z will be digits e.g. 2.28.0 at the time of writing this library contains everything you need for your first steps in Selenium. Example public static void main args Create a new instance of the Firefox driver Notice that the remainder of the code relies on the interface, not the implementation.

As this Selenium program is just a normal Java program, you have to compile the sourcecode-file. For the Java Compiler to find your Selenium library, you have to provide it in the so-called classpath . This is the composition of the classpath: 1. quote 2. the path to the folder where you put in the selenium-server-standalone- x.y.z .jar.

If everything is ok, you find Example.class in your folder.
Now Firefox should start, write “Cheese!” in google search and finally you should find in the Command Prompt: “Page title is: Google”. The browser-window is not closing, as you might admire the results for some time!

Leave a comment