Edge Options

Introduction

Edge Options is a Selenium feature that allows you to customize the behavior of the Microsoft Edge browser before it is launched. Similar to Chrome Options and Firefox Options, Edge Options enable you to configure browser startup settings, run the browser in headless mode, maximize the browser window, disable notifications, and apply other browser-specific configurations.

Microsoft Edge is built on the Chromium engine, so most Chrome command-line arguments are also supported by Edge. This makes browser configuration simple and consistent across Chromium-based browsers.

In this tutorial, you will learn what Edge Options are, why they are used, their syntax, practical examples, real-world applications, common mistakes, best practices, and frequently asked interview questions.


What are Edge Options?

Edge Options is a Selenium class that allows automation engineers to configure Microsoft Edge browser settings before creating a WebDriver instance.

Using Edge Options, you can:

  • Launch Edge in maximized mode.

  • Run Edge in headless mode.

  • Disable browser notifications.

  • Configure browser preferences.

  • Pass startup arguments.

  • Customize browser startup behavior.

Edge Options help create a consistent and reliable browser environment for Selenium automation.


Why Do We Use Edge Options?

Edge Options are commonly used to:

  • Customize browser startup.

  • Launch Edge in maximized mode.

  • Run tests in headless mode.

  • Configure browser settings.

  • Improve automation stability.

  • Create consistent browser environments.


Syntax

Create Edge Options

options = webdriver.EdgeOptions()

Add Browser Arguments

options.add_argument("--argument-name")

Launch Edge Using Options

driver = webdriver.Edge(options=options)

Practical Example

The following example demonstrates how to use Edge Options in Selenium.

The automation script creates an EdgeOptions object, starts Microsoft Edge in maximized mode, opens the Selenium practice website, and verifies the page title.

from selenium import webdriver


# Topic: 8. Browser Configuration - Edge Options
# Practice site: https://the-internet.herokuapp.com/
#
# EdgeOptions configures Microsoft Edge in the same way as ChromeOptions.


def test_edge_options():
    options = webdriver.EdgeOptions()
    options.add_argument("--start-maximized")

    driver = webdriver.Edge(options=options)

    try:
        driver.get("https://the-internet.herokuapp.com/")

        assert driver.title == "The Internet"

    finally:
        driver.quit()

Output

Edge Options created successfully.

Microsoft Edge launched with custom startup options.

Website opened successfully.

Page Title:
The Internet

Assertion Passed.

Test Executed Successfully.

Understanding the Code

Import WebDriver

from selenium import webdriver

Imports the Selenium WebDriver module.


Create Edge Options

options = webdriver.EdgeOptions()

Creates an Edge Options object to store browser configuration settings.


Add Browser Argument

options.add_argument("--start-maximized")

Configures Microsoft Edge to start in maximized mode.


Launch Edge with Options

driver = webdriver.Edge(options=options)

Starts Microsoft Edge using the configured browser options.


Open the Website

driver.get("https://the-internet.herokuapp.com/")

Navigates to the Selenium practice website.


Verify the Page Title

assert driver.title == "The Internet"

Checks that the expected webpage has loaded successfully.


Close the Browser

driver.quit()

Closes all browser windows and ends the WebDriver session.


Browser Execution Flow

Create Edge Options
        │
        ▼
Add Browser Arguments
        │
        ▼
Launch Microsoft Edge
        │
        ▼
Open Website
        │
        ▼
Verify Page Title
        │
        ▼
Assertions Pass
        │
        ▼
Close Browser

Commonly Used Edge Options

Edge OptionDescription
--start-maximizedOpens Edge in maximized mode.
--headless=newRuns Edge in headless mode.
--disable-notificationsDisables browser notifications.
--inprivateOpens Edge in InPrivate browsing mode.
--disable-popup-blockingDisables popup blocking.

Automation Testing Example

Suppose your Selenium tests are executed on a CI/CD server.

You can run Microsoft Edge in headless mode to execute tests without opening a visible browser window.

options = webdriver.EdgeOptions()

options.add_argument("--headless=new")

driver = webdriver.Edge(options=options)

This improves execution speed and allows tests to run in environments without a graphical user interface.


Real-World Example

Consider an organization where users primarily work with Microsoft Edge.

The automation framework can use Edge Options to:

  • Launch Edge in maximized mode.

  • Disable browser notifications.

  • Run tests in headless mode.

  • Configure browser startup settings.

This ensures that automated tests closely match the production environment.


Common Mistakes Beginners Make

Forgetting to Pass Edge Options

Creating Edge Options alone is not enough.

Incorrect

options = webdriver.EdgeOptions()

driver = webdriver.Edge()

Correct

driver = webdriver.Edge(options=options)

Using Invalid Browser Arguments

Only supported Edge (Chromium) command-line arguments should be used.

Incorrect

options.add_argument("--maximize-browser")

Correct

options.add_argument("--start-maximized")

Adding Arguments After Launching the Browser

Browser arguments must be configured before creating the WebDriver instance.


Best Practices

  • Configure Edge Options before launching the browser.

  • Use only the browser arguments required for your tests.

  • Use headless mode for CI/CD execution when appropriate.

  • Keep browser configuration centralized in your automation framework.

  • Test browser configurations after updating Edge versions.

  • Always close the browser using driver.quit().


Conclusion

Edge Options allow Selenium WebDriver to customize Microsoft Edge before launching the browser. They provide greater control over browser startup, improve automation stability, and help create consistent testing environments.

Since Microsoft Edge is Chromium-based, many Chrome browser arguments are also supported, making browser configuration simple and familiar for Selenium automation engineers.


Frequently Asked Questions (FAQs)

What are Edge Options in Selenium?

Edge Options allow you to configure Microsoft Edge browser settings before launching the browser.


How do I create Edge Options?

options = webdriver.EdgeOptions()

How do I launch Edge with Edge Options?

driver = webdriver.Edge(options=options)

How do I start Edge in maximized mode?

options.add_argument("--start-maximized")

When should I use Edge Options?

Use Edge Options whenever you need to customize browser startup, configure browser settings, or improve automation stability.


Key Takeaways

  • Edge Options customize Microsoft Edge browser behavior before launch.

  • Create Edge Options using webdriver.EdgeOptions().

  • Add browser arguments using add_argument().

  • Launch Edge with webdriver.Edge(options=options).

  • Edge supports most Chromium command-line arguments.

  • Edge Options are commonly used for maximized mode, headless execution, and browser configuration.

  • Configure Edge Options before creating the WebDriver instance.

  • Edge Options improve automation stability and are commonly used in Selenium frameworks.