Bird
0
0

Find the bug in this Selenium Python snippet for cross-browser testing:

medium📝 Debug Q7 of 15
Selenium Python - Cross-Browser Testing
Find the bug in this Selenium Python snippet for cross-browser testing:
from selenium import webdriver
browser = 'edge'
if browser == 'chrome':
    driver = webdriver.Chrome()
elif browser == 'firefox':
    driver = webdriver.Firefox()
else:
    driver = webdriver.EdgeOptions()
driver.get('https://example.com')
Awebdriver.EdgeOptions() used instead of webdriver.Edge()
BMissing import for Edge WebDriver
CIncorrect if-else syntax
Ddriver.get() called before driver initialization
Step-by-Step Solution
Solution:
  1. Step 1: Review driver creation for Edge

    webdriver.EdgeOptions() creates options, not the driver instance.
  2. Step 2: Correct driver initialization

    Should use webdriver.Edge() to create the driver for Edge browser.
  3. Final Answer:

    webdriver.EdgeOptions() used instead of webdriver.Edge() -> Option A
  4. Quick Check:

    Use WebDriver class, not Options class for driver [OK]
Quick Trick: Options configure driver; driver class launches browser [OK]
Common Mistakes:
  • Using Options instead of WebDriver
  • Forgetting to import Edge driver
  • Misplacing driver initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes