How to setup Selenium WebDriver?

Selenium WebDriver setup:

Step 1 : Go to the ChromeDriver downloads page and download latest ChromeDriver stable version. Download here

Once downloaded, extract the ChromeDriver executable file (chromedriver.exe for Windows, chromedriver for Unix-like systems),
Create a new folder in your desktop under Automation folder and name it driver, copy chromedriver.exe file and paste it in driver folder. Remember this location, as we’ll need it to set the WebDriver system property in your Java code.

Step 2: Write Your Selenium Test Class

Now, we can write our Selenium test class. Create a new Java class in your project and import the necessary Selenium classes when needed:

WebDriver Setup Class:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumTest {
    public static void main(String[] args) {
        // Set the path to the ChromeDriver executable
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

        // Initialize ChromeDriver
        WebDriver driver = new ChromeDriver();

        // Example: Navigate to a website
        driver.get("https://www.example.com");

        //New line of code goes here
        // Close the browser
        driver.quit();
    }
}