Bird
0
0

What is wrong with this Selenium Python workaround code for Edge browser?

medium📝 Debug Q7 of 15
Selenium Python - Cross-Browser Testing
What is wrong with this Selenium Python workaround code for Edge browser?
if driver.capabilities['browserName'] == 'edge':
    driver.execute_script('window.alert("Edge workaround")')
else:
    driver.execute_script('window.alert("Other browser")')
AEdge browserName is usually 'MicrosoftEdge', not 'edge'
Bexecute_script cannot run alert dialogs
CMissing parentheses in execute_script call
DNo error, code works as expected
Step-by-Step Solution
Solution:
  1. Step 1: Check browserName value for Edge

    Edge browserName is typically 'MicrosoftEdge', not lowercase 'edge'.
  2. Step 2: Understand condition failure

    Condition fails, so workaround code won't run as intended.
  3. Final Answer:

    Edge browserName is usually 'MicrosoftEdge', not 'edge' -> Option A
  4. Quick Check:

    Use correct browserName string for Edge = B [OK]
Quick Trick: Check exact browserName values for each browser [OK]
Common Mistakes:
  • Assuming browserName is lowercase
  • Thinking execute_script can't run alerts
  • Syntax errors in method calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes