0
0
Selenium Pythontesting~15 mins

Edge configuration in Selenium Python - Build an Automation Script

Choose your learning style9 modes available
Verify Edge browser can open a webpage with specific options
Preconditions (2)
Step 1: Launch Microsoft Edge browser with options to start maximized and disable notifications
Step 2: Navigate to 'https://example.com'
Step 3: Verify the page title is 'Example Domain'
Step 4: Close the browser
✅ Expected Result: Edge browser opens maximized without notifications, navigates to 'https://example.com', and the page title is 'Example Domain'. Browser closes successfully.
Automation Requirements - Selenium with Python
Assertions Needed:
Assert that the page title is exactly 'Example Domain'
Best Practices:
Use EdgeOptions to configure browser settings
Use explicit waits if needed
Use try-finally or context management to ensure browser closes
Use By selectors properly
Avoid hardcoded sleeps
Automated Solution
Selenium Python
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
import time

# Configure Edge options
options = Options()
options.add_argument("--start-maximized")
options.add_argument("--disable-notifications")

# Initialize Edge driver with options
service = Service()  # Assumes msedgedriver is in PATH

try:
    driver = webdriver.Edge(service=service, options=options)
    driver.get("https://example.com")

    # Verify page title
    assert driver.title == "Example Domain", f"Expected title 'Example Domain' but got '{driver.title}'"

finally:
    driver.quit()

This script starts by importing necessary Selenium classes for Edge browser automation.

We create an Options object to add arguments that start the browser maximized and disable notifications, matching the manual test case requirements.

The Service object is created without arguments assuming the Edge WebDriver executable is in the system PATH.

We then create the Edge driver with these options and navigate to 'https://example.com'.

An assertion checks that the page title exactly matches 'Example Domain'. If not, it raises an error with a clear message.

Finally, the driver.quit() call in the finally block ensures the browser closes even if the assertion fails or an error occurs.

Common Mistakes - 4 Pitfalls
Not using EdgeOptions to configure browser settings
Hardcoding sleep() calls instead of using waits
Not closing the browser properly after test
Assuming WebDriver executable path without setting or verifying
Bonus Challenge

Now add data-driven testing to open three different URLs with the same Edge configuration and verify their titles.

Show Hint