Selenium 3 – Launch Edge Browser with MicrosoftWebDriver

With the release of Selenium 3.0 Beta version and newer versions of different browsers, there have been slight changes in the way you launch different browsers. In our previous article, we had described the process of launching Firefox with GeckoDriver. In this article you will see how to launch Microsoft Edge browser by using MicrosoftWebDriver.

Prerequisites for using MicrosoftWebDriver

Before you start automation with Microsoft Edge browser using Selenium , you need to make sure that –

1. You have windows 10 installed on your machine

2. Download the correct Microsoft WebDriver server version for your OS build.

3. Preferably, use the latest version of Selenium (version 3.0 and above)

Download MicrosoftWebDriver

Follow the steps given below to download Microsoft Edge Driver –

1. The first step is to check the version of your OS build. Based on your OS version build, you have to download the corresponding Edge driver.

2. Go to Start > Settings > System > About. The settings window would be displayed as shown below.

3. Note down the number written next to OS Build. This is your build number. In my case its 10586, as shown in the red rectangle in the above image

4. Open Microsoft Edge Webdriver page using this link – https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

5. Scroll down a bit till you see the Downloads section, as shown below

6. From the list of different versions of Edge drivers, download the one which matches your build number. In this case, I will download Release 10586

7. If you are downloading Release 10240 or 10586, then the file that will be downloaded is MicrosoftWebDriver.msi. You will then need to install this msi file to get the actual MicrosoftWebDriver.exe driver. But if you are downloading Release 14393, then it directly downloads the MicrosoftWebDriver.exe driver. In this case you don’t need to install it.

8. In this scenario we will get the msi file, as we downloaded Release 10586.

9. Install the msi file. Select all default details while installing the msi file. Note down the location where the driver will be installed. This will be displayed in the window shown in the below image

10. Once the installation is complete, go to the folder path to check that webdriver is properly installed.

This completes the download and installation process. Let us now see how we can use this driver to launch Microsoft Edge.

Launch Microsoft Edge using MicrosoftWebDriver

Just like we did with Firefox & GeckoDriver,there are 2 ways of using MicrosoftWebDriver.

Method 1 : webdriver.edge.driver system property

When you use this method, you will need to just need to add a line of code to your test script to use MicrosoftWebDriver. You will need to add System.setProperty code in your script. The entire script is shown below –

public class MicrosoftEdgeTest {
	
	@Test
	public void MicrosoftEdge_Test1() {
		System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe");
		WebDriver driver = new EdgeDriver();
		driver.get("http://www.google.com");
	}
}

Run this test script. You will see that a new Edge browser is opened and Google.com page is loaded in the web browser. This verifies that the webdriver.edge.driver system property is working fine.

Method 2 : Set property in Environment Variables

1. Copy the entire folder location where MicrosoftWebDriver.exe is saved.

2. Open Advanced tab in System Properties window as shown in below image.

3. Open Environment Variables window.

4. In System variables section, select the Path variable (highlighted in red in the above image) and click on Edit button. Then add the location of the webdriver to path variable.

5. Once the path variable is set, you would not need to set the System property every time in the test script. Your test script would simply look like this –

public class MicrosoftEdgeTest {
	
	@Test
	public void MicrosoftEdge_Test1() {
		WebDriver driver = new EdgeDriver();
		driver.get("http://www.google.com");
	}
}

6. Run the code to check that it works fine. You might need to restart eclipse once, after you set the system variable


This was all about using MicrosoftWebDriver to launch Microsoft Edge browser. Try it out and let us know if you face any issues while implementing this.

We have already written an article on launching Firefox with GeckoDriver. We will be adding many more articles on Selenium in this blog. You can subscribe to our blog to get new articles delivered directly in your inbox.