Selenium + Python · Lesson 39 of 43

0/43 done

Module 39: Cross-Browser Testing

39. Dynamic Multi-Browser Driver Factory in Python

16 minlesson

Your task

Implement normalize_browser(browser_str):

  1. Return browser_str.strip().lower() if browser_str else "chrome".

Write it in the editor, then press Check answer (Ctrl + Enter).

Driver Factory in Python

python
from selenium import webdriver

def create_driver(browser_name: str = "chrome"):
    b = browser_name.lower().strip()
    if b == "firefox":
        return webdriver.Firefox()
    elif b == "edge":
        return webdriver.Edge()
    else:
        return webdriver.Chrome()

Key Takeaways & Walkthrough Summary

Your users use different browsers. In this lesson, you will create a flexible browser factory that instantiates Chrome, Firefox, or Edge based on configuration. Let's build a cross-browser factory!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Can I run Edge on Linux/macOS?

Yes, Microsoft Edge is available for Linux and macOS and is fully supported by Selenium.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip