How can I run selenium scripts on Edge headless browser

10,073

Here, I assume that you are trying to automate the MS Edge Chromium browser and you want to run selenium tests on the MS Edge browser in headless mode.

You can refer to the steps below.

  1. Download the Java/C# binding of Selenium 4.00-alpha05 from here.

  2. Download the matching version of Microsoft Edge Driver from this page.

Example C# code.

using OpenQA.Selenium.Edge;
using System.Threading;
namespace ecwebdriver
{
    public class edgewebdriver
    {
        static void Main(string[] args)
        {
            EdgeOptions edgeOptions = new EdgeOptions();
            edgeOptions.UseChromium = true;
            edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
            edgeOptions.AddArgument("headless");
            edgeOptions.AddArgument("disable-gpu");
            var msedgedriverDir = @"E:\webdriver";
            var driver = new EdgeDriver(msedgedriverDir, edgeOptions);
            driver.Navigate().GoToUrl("<website url>");
            Thread.Sleep(3000);
            driver.Close();
        }
    }
}

JAVA Example code:

package selenium_test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.*;

public class new_java_class 
{
        public static void main(String[] args) 
    {
         System.setProperty("webdriver.edge.driver","D:\\edgedriver_win64_83.0.478.45\\msedgedriver.exe");
         EdgeOptions op=new EdgeOptions();
                 op.addArguments("headless");
                 WebDriver browser = new EdgeDriver(op);
                 browser.get("https://microsoft.com");

    }
}

Note: Change the paths and modify the values in above code as per your own requirements.

You can download the Selenium 4.00-alpha05 on any path. you need to add it in your JAVA project by add External Jars option.

enter image description here

Share:
10,073
ankita garge
Author by

ankita garge

Updated on June 04, 2022

Comments

  • ankita garge
    ankita garge almost 2 years

    I want to run my scripts in Edge browser in headless mode.But I am not able to find any proper solution for it. Can anyone suggest on this

    • Hoppo
      Hoppo almost 4 years
      What research have you done to not be able to find any help on this? Google is your friend my friend. Try entering "edge selenium"
  • ankita garge
    ankita garge almost 4 years
    Can I get t in Java as I am using Java in my framework.And using this code I am getting errors. Also, on which path I download this Java/C# binding of Selenium 4.00-alpha05
  • Deepak-MSFT
    Deepak-MSFT almost 4 years
    Please refer to the updated answer. I have added the JAVA code sample.
  • anandhu
    anandhu over 3 years
    I am not able to set values to edgeoptions. it says UseChromium ,BinaryLocation etc are not member of edgeoptions. any idea? i have done the import correctly as Imports OpenQA.Selenium.Edge
  • anandhu
    anandhu over 3 years
    Does chromium Edge support headless execution if launched in IE Capability Mode?
  • Deepak-MSFT
    Deepak-MSFT over 3 years
    Running the Edge chromium-browser in IE mode will put the whole browser in an IE mode. Headless execution is not supported by the IE browser. so it will also not work when you try to automate the Edge chromium-browser in an IE mode.
  • Rashid
    Rashid over 2 years
    This didn't work, the browser window is still getting opened. And addArguments() method is not present in org.openqa.selenium.edge.EdgeOptions but its in com.microsoft.edge.seleniumtools.EdgeOptions
  • quiram
    quiram over 2 years
    Is it possible do run Edge in headless mode with Selenium 3.x?