Bird
0
0

Given this custom expected condition class: class ElementHasText: def __init__(self, locator, text): self.locator = locator self.text = text def __call__(self, driver): element = driver.find_element(*self.locator) return self.text in element.text What will WebDriverWait(driver, 5).until(ElementHasText((By.ID, 'msg'), 'Success')) do if the element's text is 'Operation Success'?

medium📝 Predict Output Q4 of 15
Selenium Python - Advanced Patterns
Given this custom expected condition class: class ElementHasText: def __init__(self, locator, text): self.locator = locator self.text = text def __call__(self, driver): element = driver.find_element(*self.locator) return self.text in element.text What will WebDriverWait(driver, 5).until(ElementHasText((By.ID, 'msg'), 'Success')) do if the element's text is 'Operation Success'?
ARaise TimeoutException immediately
BWait until the element's text contains 'Success' and then return True
CReturn False without waiting
DRaise NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition logic

    The condition checks if 'Success' is in the element's text.
  2. Step 2: Analyze the element's text 'Operation Success'

    'Success' is a substring, so condition returns True immediately.
  3. Final Answer:

    Wait until the element's text contains 'Success' and then return True -> Option B
  4. Quick Check:

    Condition returns True if text found, so wait passes [OK]
Quick Trick: Condition returns True when text is found in element [OK]
Common Mistakes:
  • Assuming exact match needed instead of substring
  • Expecting immediate exception if text not found yet
  • Confusing return False with raising exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes