Running Test on Chrome

Step 1: Install ChromeDriver

  • ChromeDriver is a driver that allows Selenium WebDriver to communicate with the Chrome browser. Download the latest version of ChromeDriver from here.

  • Select the link which is compatible with your operating system. Download and extract the (e.g., chomredriver_win32.zip).

  • After downloading the zip file, extract the zip file and copy the path of the chromedriver.exe
    (e.g., D:\chromedriver_win32\chromedriver.exe).

Step 2: Create a new Java project in Eclipse IDE

  • In Eclipse, go to File > New > Java Project.
  • Next, a pop-window appears Give a name to your project, such as (SeleniumTest), and click Finish.

Step 3: Add Selenium WebDriver jar files to your Project Classpath

  • In Eclipse, right-click on your project name and select Properties.
  • In the Properties window, select Java Build Path from the left panel and click on the Libraries tab from the right panel.
  • Click on the Add External JARs button and browse to the location where you saved the Selenium WebDriver files, select all the jar files (inside the lib folder also), and click Open. Click Appy and close the Properties window.

Step 4: Create a new Java class in your Project

  • In Eclipse, right-click on the src folder under your project name and select New > Class. Give a name to your class, such as TestChrome, and click Finish.

Example

Below is the Java program to retrieve title of the website:

Java




// Java program to retrieve title of the website
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
  
public class TestChrome {
    public static void main(String[] args)
    {
        // Set the path of chromedriver.exe file
        System.setProperty(
            "webdriver.chrome.driver",
            "D:/chromedriver_win32/chromedriver.exe");
  
        // Create an instance of ChromeDriver class
        WebDriver driver = new ChromeDriver();
  
        // Navigate to a web page
        driver.get("https://www.w3wiki.org/");
  
        // Get the title of the web page
        String title = driver.getTitle();
  
        // Print the title
        System.out.println("Page Title: " + title);
  
        // Close the browser
        driver.quit();
    }
}


Explanation:

  • The above program opens a Chrome web browser using Selenium WebDriver, navigates to the w3wiki homepage (https://www.w3wiki.org/).
  • It retrieves the title of the page, and prints the title to the console.
  • Then, it closes the browser and ends the WebDriver session.

Output:



How to run Selenium Running Test on Chrome using WebDriver

Selenium is a popular open-source tool for automating web browser interactions. It works with different web browsers like Chrome, Firefox, and more, and different programming languages like Python or Java to write tests.

Similar Reads

What is a Selenium ChromeDriver?

ChromeDriver is a separate executable that Selenium WebDriver uses to launch and control Chrome. It implements the WebDriver protocol, which is a set of RESTful HTTP endpoints used to communicate between the test script and the browser....

Prerequisites

1. Install Java on your system....

Running Test on Chrome

Step 1: Install ChromeDriver...