How to launch Edge Browser in Selenium

Profile picture for user ksharma

Microsoft Edge is a cross-platform web browser developed by Microsoft. First make sure that Microsoft Edge browser is already installed on your system. To launch Microsoft Edge browser using Selenium follow below steps:

Step 1: Check you Edge Browser version. By clicking on ... (3 dots on top right corner of browser) then Help and Feedback -> About Microsoft Edge

edge browser selenium webdriver

desired capabilities in selenium for edge browser

Step 2: Open this link or Search in google microsoft edge webdriver and download the version compatible with your browser and operating system. 

selenium webdriver for edge browser

Step 3: Unzip the file and paste driver to your desired directory.

Step 4: Now open your driver configuration file and paste following code. Since we have not introduced TestNG or JUnit yet, we will be executing this with Java runner using main class.

package com.pb.sel.seltest;

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

public class App 
{
	public static void main(String args[])
	{
		System.setProperty("webdriver.edge.driver",System.getProperty("user.dir") + "//drivers//msedgedriver.exe");
		
		WebDriver driver;
		driver = new EdgeDriver();
		driver.get("http://www.automationpractice.com");
	}
}

In above code,

  • setProperty will set the system property to value webdriver.edge.driver and the path is given to get the msedge driver.
  • Here WebDriver is the main interface and all the methods which are declared in Webdriver interface are implemented by respective driver class.
  • new EdgeDriver(), Here we are creating instance of EdgeDriver class.
  • driver.get() is used to navigate to given url.