First Selenium WebDriver Test case – Selenium WebDriver Testing Free Training

Updated on Fri 5 Aug, 2022 | 4 mins read | automation testing training, Free training, qa training, selenium testing training

Welcome to the Selenium WebDriver Testing Free Training series. In this tutorial, we are going to talk about how to write the first Selenium WebDriver code with Java programming.


Before moving further, here are some prerequisites that you should have :


  1. JDK 11
  2. Intermediate knowledge of Java
  3. Eclipse
  4. Eclipse Project with Selenium Java library
  5. Chrome Browser
  6. Compatible Chrome driver with Chrome Browser. To download the chrome driver, please use the following URL:
Before writing the first code, let’s have quick a discussion, on what is Selenium WebDriver? And why is it famous in the testing industry?

What is Selenium Webdriver?

Selenium WebDriver is an open-source tool that is used to test web applications. The Selenium WebDriver tool is used for automating web application testing to verify & validate the expected outcome. It primarily supports browsers like Firefox, Chrome, Safari, and Internet Explorer. It also allows you to execute cross-browser testing.

Selenium WebDriver provides different programming libraries to write test scripts that are the following:

  1. Java
  2. C#
  3. Ruby
  4. Python
  5. JavaScript

To get more detail, please refer to the following URL:

Important note: we like to tell you that free tutorials are useful to get started but if you are interested in the best online LIVE Master of Automation Testing training program from the experts, please refer to the following link:

For Instructor-led training

Master of Functional Automation Testing

For Self-Driven training

Automation with Selenium WebDriver (Java)

Let’s come to the next question,

why is it so famous in the testing industry?

  1. It is an open-source tool.
  2. It provides multilingual programming support.
  3. Furthermore, it supports multiple OS like Linux, UNIX, Mac, and Windows.
  4. It supports all the major browsers so that you could test on Chrome, Firefox, Safari, Opera, IE, Edge, Yandex, and many more. When you execute cross-browser testing of a website, it provides you with an automated solution.
  5. It can be integrated with various frameworks, like Maven or ANT, for building, and compiling the source code. For application testing and reporting, it can be integrated with testing frameworks like TestNG, and JUnit. For Continuous Integration or Continuous Delivery, It can integrate with Jenkins for automated build and deployment.
  6. User-friendliness of Selenium WebDriver is one of the benefits of Selenium WebDriver for automation testing.
  7. The test scripts written using Selenium WebDriver support cross-browser testing. So, a tester can run multiple testing scenarios since it covers every functionality testing aspect. The add-ons that can be customized extend the scope of testing an application, serving great benefits of automation testing with Selenium WebDriver.
  8. WebDriver provides the benefit of speeding up the test cycles by leveraging the development code. Testers can use the language used by developers.

So far, we have discussed the Selenium WebDriver and its popularity. Let’s see how to write our first Selenium WebDriver code:

Import Note: please make sure, you have imported the Selenium Java library to the project.

In this simple test case, we are just going to open the Google page.

First Selenium Webdriver script

package seleniumWebDriverCodes;
public class OpeningWebsiteChrome {
    public static void main(String[] args) {     
// please set the path where your webdriver file lies in your system
// for Mac: should be like, "\User\name_of_user\Downloads\chromedriver"
        System.setProperty("", "C:\\Program Files\\chromedriver.exe" );
        ChromeDriver driver = new ChromeDriver();
The above code will open in the Google Chrome browser by running the code. Well, It is our first code, so let’s discuss important code snippets:

1. System.setProperty(“”, “pleaseprovideabsolutepathofchromedriver” ); 

This code snippet is setting up the chrome driver location to open the Chrome browser. Please replace pleaseprovideabsolutepathofchromedriver with the absolute path of chrome driver location on your system.

2.  ChromeDriver driver = new ChromeDriver();

This code snippet is creating a ChromeDriver class object. ChromeDriver class is importing through (that you can see in the import section) library.

3. driver.get(“”);

The above snippet is called the get method and passes URL as an argument to open in the Google Chrome browser.


All right!! So, this is our first simple selenium code to open up in Google Chrome. Please copy the code and try to run.
→ The upcoming article in this Selenium WebDriver Testing Free Training series will be aboutgetting the Web page title and asserting the title.

Happy learning, until then!