Bird
0
0

What will happen if you call a Base Page method that uses driver.findElement(By.id("submit")) but the element is not present on the page?

medium📝 Predict Output Q5 of 15
Selenium Java - Page Object Model
What will happen if you call a Base Page method that uses driver.findElement(By.id("submit")) but the element is not present on the page?
AStaleElementReferenceException is thrown
BNoSuchElementException is thrown immediately
CMethod returns null without error
DMethod waits indefinitely for element
Step-by-Step Solution
Solution:
  1. Step 1: Recall findElement behavior

    findElement throws NoSuchElementException if element is not found immediately.
  2. Step 2: Confirm no implicit wait in method

    Without explicit wait, it throws exception right away.
  3. Final Answer:

    NoSuchElementException is thrown immediately -> Option B
  4. Quick Check:

    findElement missing element = NoSuchElementException [OK]
Quick Trick: findElement throws NoSuchElementException if missing [OK]
Common Mistakes:
  • Expecting null return instead of exception
  • Confusing with StaleElementReferenceException
  • Assuming implicit wait delays exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes