Bird
0
0

Analyze this Selenium Python snippet for CAPTCHA handling:

medium📝 Debug Q6 of 15
Selenium Python - Advanced Patterns
Analyze this Selenium Python snippet for CAPTCHA handling:
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://example.com')
input('Solve CAPTCHA then press Enter')
driver.find_element('id', 'submit').click()

What is the main issue with this code?
AUsing 'id' as a string directly instead of By.ID locator causes an error
BThe input() function blocks the script, preventing automation
CThe driver is not closed after the test, causing resource leaks
DThe CAPTCHA cannot be solved manually with this approach
Step-by-Step Solution
Solution:
  1. Step 1: Check element locator usage

    Using 'id' as a string in find_element is invalid; Selenium expects a locator strategy.
  2. Step 2: Correct locator usage

    Should use: driver.find_element(By.ID, 'submit').click()
  3. Final Answer:

    Using 'id' as a string directly instead of By.ID locator causes an error -> Option A
  4. Quick Check:

    Locator strategy must be specified [OK]
Quick Trick: Always use By.ID or similar locators, not strings [OK]
Common Mistakes:
  • Passing locator as string instead of using By class
  • Assuming input() is problematic for manual CAPTCHA
  • Ignoring driver cleanup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes