Bird
0
0

Identify the error in this custom expected condition class:

medium📝 Debug Q14 of 15
Selenium Python - Advanced Patterns
Identify the error in this custom expected condition class:
class ElementHasText:
    def __call__(self, driver):
        element = driver.find_element(By.ID, 'msg')
        if element.text:
            return element.text
        else:
            return False
AMissing import for By from selenium.webdriver.common.by
BThe __call__ method should return True or False only, not text
CThe class should inherit from WebDriverWait
DThe find_element method should be find_elements
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of By.ID in the code

    The code uses By.ID but does not import By, causing a NameError.
  2. Step 2: Verify other parts of the code

    Returning element.text is valid for expected conditions; inheritance from WebDriverWait is not required.
  3. Final Answer:

    Missing import for By from selenium.webdriver.common.by -> Option A
  4. Quick Check:

    Using By requires importing it first [OK]
Quick Trick: Always import By before using it [OK]
Common Mistakes:
  • Assuming __call__ must return only True/False
  • Thinking class must inherit WebDriverWait
  • Confusing find_element with find_elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes