How to run Selenium Scripts on Edge Browser

  

1. Setup Prerequisites

 

2. Add WebDriver to System PATH

Place the msedgedriver.exe in a known directory (e.g., C:\WebDriver) and add that path to the system environment variable PATH.


3. Basic Selenium Java code for Edge browser

Here’s a complete example:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class EdgeTest {
    public static void main(String[] args) {
        // Set system property (optional if msedgedriver is in PATH)
        System.setProperty("webdriver.edge.driver", "C:\\WebDriver\\msedgedriver.exe");

        // Create instance of EdgeDriver
        WebDriver driver = new EdgeDriver();

        // Open a website
        driver.get("https://www.google.com");

        // Print the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        // Close browser
        driver.quit();
    }
}


4. Add Selenium Libraries to Project

In Eclipse or IntelliJ:

  • Right-click on project > Build Path > Add External Archives

  • Add all JARs from Selenium zip (selenium-java-X.X.X.zip)


5. Run the Program

  • Run the Java class as a Java application.

  • Edge browser should launch and navigate to Google.

No comments:

Post a Comment