CAPTCHAs are designed to prevent automated access. Why is it generally discouraged to automate CAPTCHA solving in test scripts?
Think about the purpose of CAPTCHAs and ethical testing practices.
CAPTCHAs are meant to block bots. Automating their solving can break website rules and cause flaky tests. It's better to avoid or bypass them in testing.
Given the following Selenium Python code snippet, what will be the output if the CAPTCHA iframe is not present on the page?
from selenium import webdriver from selenium.common.exceptions import NoSuchElementException try: driver = webdriver.Chrome() driver.get('https://example.com') captcha_frame = driver.find_element('css selector', 'iframe[src*="captcha"]') print('CAPTCHA iframe found') except NoSuchElementException: print('CAPTCHA iframe not found') finally: driver.quit()
Consider what exception is caught when an element is missing.
If the iframe is missing, Selenium raises NoSuchElementException, which is caught and prints 'CAPTCHA iframe not found'.
You want to locate the CAPTCHA checkbox element reliably. Which locator is best practice?
Think about locator stability and specificity.
Using a unique ID like 'recaptcha-anchor' is stable and specific. XPath with indexes or generic class names are fragile and may break easily.
Given a Selenium test that should verify CAPTCHA is displayed, which assertion is correct?
captcha_element = driver.find_element('id', 'captcha')
Check how to verify element visibility in Selenium.
To confirm CAPTCHA is visible, use is_displayed() method. Checking element existence or text is not enough.
In a test automation framework, what is the best strategy to handle CAPTCHA challenges to keep tests reliable and maintainable?
Think about test reliability and automation best practices.
Disabling CAPTCHA in test environments and mocking responses avoids flaky tests and respects ethical boundaries. Other options cause delays, errors, or unreliable tests.