Bird
0
0

What is the issue with this custom expected condition class?

medium📝 Debug Q6 of 15
Selenium Python - Advanced Patterns
What is the issue with this custom expected condition class?
class ElementClickable:
    def __init__(self, locator):
        self.locator = locator
    def __call__(self, driver):
        element = driver.find_element(self.locator)
        return element.is_enabled() and element.is_displayed()
AThe class is missing an explicit wait inside __call__
BThe method __call__ should return the element instead of a boolean
CThe locator should be unpacked with *self.locator in find_element
DThe constructor should accept driver as a parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand locator usage

    In Selenium, locators are tuples like (By.ID, 'id'). The find_element method requires unpacking the tuple.
  2. Step 2: Identify the error

    Using driver.find_element(self.locator) passes the tuple as a single argument, causing an error.
  3. Step 3: Correct usage

    It should be driver.find_element(*self.locator) to unpack the tuple into separate arguments.
  4. Final Answer:

    The locator should be unpacked with *self.locator in find_element -> Option C
  5. Quick Check:

    Always unpack locator tuples with * [OK]
Quick Trick: Unpack locator tuples with * in find_element [OK]
Common Mistakes:
  • Passing locator tuple directly without unpacking
  • Returning boolean instead of element (not always required)
  • Expecting __call__ to include waits internally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes