0
0
Selenium Pythontesting~10 mins

Handling CAPTCHAs (strategies) in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to pause the test and let the tester solve the CAPTCHA manually.

Selenium Python
input('Please solve the CAPTCHA and press Enter to continue...')  # [1]
Drag options to blanks, or click blank then click option'
Ainput
Bwait
Csleep
Dpause
Attempts:
3 left
💡 Hint
Common Mistakes
Using sleep() only waits a fixed time and does not wait for user action.
Using pause or wait are not valid Python functions.
2fill in blank
medium

Complete the code to detect if a CAPTCHA element is present on the page.

Selenium Python
captcha_present = len(driver.find_elements(By.ID, '[1]')) > 0
Drag options to blanks, or click blank then click option'
Acaptcha
Bcaptcha_element
Ccaptcha_box
Dcaptcha_image
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect or uncommon element IDs.
Using find_element instead of find_elements which throws error if not found.
3fill in blank
hard

Fix the error in the code that tries to click the CAPTCHA checkbox but fails if not found.

Selenium Python
try:
    driver.find_element(By.ID, '[1]').click()
except NoSuchElementException:
    print('CAPTCHA checkbox not found')
Drag options to blanks, or click blank then click option'
Acaptcha
Bcaptcha_check
Ccaptcha_box
Dcaptcha_checkbox
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic 'captcha' ID that does not match the checkbox.
Not handling exceptions causing test to crash.
4fill in blank
hard

Fill both blanks to create a wait that pauses until the CAPTCHA iframe is visible.

Selenium Python
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.[1], '[2]')))
Drag options to blanks, or click blank then click option'
ATAG_NAME
Biframe
CID
Dclass_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using FRAME instead of TAG_NAME causes errors.
Using ID or class_name without correct values.
5fill in blank
hard

Fill all three blanks to switch to the CAPTCHA iframe, solve it manually, then switch back.

Selenium Python
driver.switch_to.[1](driver.find_element(By.[2], '[3]'))
input('Solve CAPTCHA and press Enter...')
driver.switch_to.default_content()
Drag options to blanks, or click blank then click option'
Aframe
BTAG_NAME
Ciframe
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using switch_to.frames (plural) instead of frame (singular).
Using incorrect locator types like id with wrong values.