We use Edge configuration to set up Microsoft Edge browser for automated tests. It helps control browser settings before running tests.
0
0
Edge configuration in Selenium Python
Introduction
When you want to run automated tests on Microsoft Edge browser.
When you need to customize browser options like headless mode or window size.
When you want to add browser extensions or disable pop-ups during tests.
When you want to run tests on Edge with specific user profiles or preferences.
Syntax
Selenium Python
from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options options = Options() # Set options like options.add_argument('--headless') service = Service(executable_path='path_to_edge_driver') driver = webdriver.Edge(service=service, options=options)
Use Options() to customize Edge browser settings.
Use Service() to specify the Edge driver executable path.
Examples
This example runs Edge in headless mode (no browser window shown).
Selenium Python
from selenium import webdriver from selenium.webdriver.edge.options import Options options = Options() options.add_argument('--headless') driver = webdriver.Edge(options=options)
This example sets the path to the Edge driver executable.
Selenium Python
from selenium import webdriver from selenium.webdriver.edge.service import Service service = Service(executable_path='C:/drivers/msedgedriver.exe') driver = webdriver.Edge(service=service)
This example starts Edge browser maximized.
Selenium Python
from selenium import webdriver from selenium.webdriver.edge.options import Options options = Options() options.add_argument('--start-maximized') driver = webdriver.Edge(options=options)
Sample Program
This script opens Microsoft Edge in headless mode, navigates to example.com, prints the page title, then closes the browser.
Selenium Python
from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options import time options = Options() options.add_argument('--headless') # Run Edge without opening window service = Service(executable_path='msedgedriver') # Adjust path if needed driver = webdriver.Edge(service=service, options=options) driver.get('https://example.com') print('Title:', driver.title) time.sleep(1) # Wait a moment driver.quit()
OutputSuccess
Important Notes
Make sure the Edge WebDriver version matches your installed Edge browser version.
Use absolute path for the Edge driver executable to avoid errors.
Headless mode is useful for running tests on servers without a display.
Summary
Edge configuration lets you control Microsoft Edge browser settings for tests.
Use Options() to add arguments like headless or window size.
Use Service() to specify the Edge driver location.