How to Run Edge Driver in Selenium Using Eclipse? (original) (raw)

Last Updated : 22 Sep, 2023

**Selenium is a well-known software used for software testing purposes. Selenium consists of 3 parts. One is Selenium IDE, one is **Selenium Webdriver & the last one is **Selenium Grid. Among these Selenium Webdriver is the most important one. Using webdriver online website testing can be done. There are 3 main webdrivers present.
For the Chrome browser, ChromeDriver is present. For the Firefox browser, Gecko Driver is applicable. And for Microsoft Edge, there will be MSEdgeDriver present. In this article, the process of running EdgeWebdriver is implemented. This simple Java program can be run.

**Pre-Requisite required is as follows:

Approach:

Here, using EdgeDriver, the home page of Google is going to open. For, that some methods need to be imported.

**Step 1: The Google home page link is to be stored in a string.

**Step 2: Then in a program, the property of the browser is to be set. setproperty() method is going to be used here.

**Step 3: In the setProperty() method, the first argument is to be the web driver that is to be used. Here, using EdgeDriver specifically that argument has to be passed. And in the second argument, the location of the EdgeDriver.exe is to be passed.

**Note: In this case, EdgeDriver.exe is stored in Eclipse, so may be the location seems different. But also, a complete File Explorer path can also be passed.

**Step 4: Then a new object called driver should be implemented which is a type of WebDriver. Here, in this case, it will be EdgeDriver.

**Step 5: Then using that driver object, the get() method will be used. This get() method of webDrivers helps to open some URLs provided. Here the home page of Google is going to be opened. So, only the string where the URL has been stored will be passed. Executing this method will open a new Edge window.

**Step 6: Then the sleep() method is going to be implemented. This delays the programs for some time. So that the output can be visible easily.

**Step 7: At last, the opened Edge window has to be closed. For that reason, the quit() method is going to be implemented.

Implementation:

Java `

// Java Program to Illustrate Run for Edge Driver // In Selenium Using Eclipse

// Importing All Necessary Items import java.io.*; import java.lang.Thread; import org.openqa.selenium.WebDriver; import org.openqa.selenium.edge.EdgeDriver;

// Class public class EdgeHomePage {

// Main driver method
public static void main(String[] args)
{

    // Try block as we will be using sleep() method
    try {

        // String Where Home Page URL Is Stored
        String baseUrl = "https://www.google.com/";

        // Implementation of SetProperty Method
        System.setProperty(
            "webdriver.edge.driver",
            "test/resources/msedgedriver.exe");

        // Creating new Object driver Of Webdriver
        WebDriver driver = new EdgeDriver();

        // Calling Home Page by
        // using Get() Method
        driver.get(baseUrl);

        // Making output delayed
        // by 2 seconds
        Thread.sleep(2000);

        // Closing The Opened Window
        // using quit() method
        driver.quit();
    }

    // Catch block to handle exceptions
    catch (Exception e) {

        // Display exceptions on the console
        System.out.println(e);
    }
}

}

`

**Output:

If the above code is run, then a new Edge Window will be opened. This open window will be controlled by EdgeDriver.exe.