Skip to content
Related Articles

Related Articles

How to Open Microsoft Edge Browser using Selenium in Java?

View Discussion
Improve Article
Save Article
  • Last Updated : 05 Apr, 2022

Selenium is an open-source popular web-based automation tool. The major advantage of using selenium is, it supports all browsers like Google Chrome, Microsoft Edge, Mozilla Firefox, and Safari, works on all major OS and its scripts are written in various languages i.e Java, Python, JavaScript, C#, etc. We will be working with Java. In this article, let us consider a test case in which we will try to automate the following scenarios in the Edge browser.

For invoking the chrome browser, we need the Eclipse IDE, Selenium Grid(version 4), and Edge Driver.

Note: To open Chrome Browser Using Selenium please refer to this article How to Open Chrome Browser Using Selenium in Java?

Installation

Step By Step Implementation

Step 1:

Open the Eclipse IDE and create a new Java project. Right-click on the “src” folder and create a new Class File from New > Class. Give the Class name and click on the “Finish” button.

Step 2:

Add Selenium JAR file into the Java Project. Right-click on Class name and Select “Build Path” and select > configure build path

Then select Libraries > Classpath > and Click “Add External JAR”, now add the Selenium Jar and click “Apply and Finish”

Java




import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
 
public class Geeksforgeeks {
    public static void main(String args[])
    {
        System.setProperty(
            "webdriver.edge.driver",
            "C:\\Users\\ADMIN\\Documents\\Selenium\\msedgedriver.exe");
        // Instantiate a ChromeDriver class.
        WebDriver driver = new EdgeDriver();
        // Maximize the browser
        driver.manage().window().maximize();
        // Launch Website
        driver.get("https://www.geeksforgeeks.org/");
    }
}


Studying the code

The above script is for opening Microsoft Edge Browser and navigating to geeksforgeeks website. So let’s see how it works:

  • Set a system property “webdriver.edge.driver” to the path of your EdgeDriver.exe file and instantiate an EdgeDriver class:

System.setProperty(“webdriver.edge.driver” ,”edgedriver location”); 

  • Maximize the window: driver.manage().window().maximize();  
  • To open the URL: driver.get(“URL link”)

Refer this video if any doubts

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!