Bird
0
0

What will the following code print if the browser is Firefox?

medium📝 Predict Output Q13 of 15
Selenium Python - Cross-Browser Testing
What will the following code print if the browser is Firefox?
browser = driver.capabilities['browserName']
if browser == 'firefox':
    print('Use Firefox workaround')
else:
    print('Use default code')
AUse default code
BUse Firefox workaround
CKeyError
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Check browser value

    The variable browser is assigned driver.capabilities['browserName'], which is 'firefox' here.
  2. Step 2: Evaluate if condition

    Since browser == 'firefox' is True, the code prints 'Use Firefox workaround'.
  3. Final Answer:

    Use Firefox workaround -> Option B
  4. Quick Check:

    Browser is 'firefox' so prints Firefox workaround [OK]
Quick Trick: Match browserName string exactly to choose workaround [OK]
Common Mistakes:
  • Assuming else branch runs for Firefox
  • Confusing case sensitivity in browser name
  • Expecting errors when key exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes