Bird
0
0

Find the mistake in this Selenium Python code for cross-browser testing:

medium📝 Debug Q6 of 15
Selenium Python - Cross-Browser Testing
Find the mistake in this Selenium Python code for cross-browser testing:
from selenium import webdriver
browser = 'firefox'
if browser == 'chrome':
    driver = webdriver.Chrome()
else:
    driver = webdriver.FirefoxOptions()
driver.get('https://example.com')
Adriver.get() is called before driver initialization
BThe URL is missing the protocol (http/https)
CThe 'browser' variable should be capitalized
Dwebdriver.FirefoxOptions() is used instead of webdriver.Firefox() to initialize the driver
Step-by-Step Solution
Solution:
  1. Step 1: Analyze driver initialization

    webdriver.FirefoxOptions() returns options, not a driver instance.
  2. Step 2: Correct usage

    Should use webdriver.Firefox() to create the driver object.
  3. Final Answer:

    webdriver.FirefoxOptions() is used instead of webdriver.Firefox() to initialize the driver -> Option D
  4. Quick Check:

    Use WebDriver classes, not Options, to instantiate drivers [OK]
Quick Trick: Use WebDriver(), not Options(), to create driver [OK]
Common Mistakes:
  • Confusing Options with WebDriver
  • Ignoring proper driver initialization
  • Assuming Options can replace driver

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes