Bird
0
0

Given the code snippet:

medium📝 Predict Output Q4 of 15
Selenium Java - Page Object Model
Given the code snippet:
@FindBy(id = "submitBtn")
private WebElement submitButton;

public void clickSubmit() {
    submitButton.click();
}

What will happen if the element with id "submitBtn" is not present on the page when clickSubmit() is called?
AA <code>NoSuchElementException</code> is thrown at runtime.
BNo exception; the click is silently ignored.
CA <code>NullPointerException</code> is thrown because submitButton is null.
DThe test will fail at compile time.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @FindBy element initialization

    @FindBy initializes elements lazily. When submitButton.click() is called, Selenium tries to find the element on the page.
  2. Step 2: Behavior if element is missing

    If the element with id "submitBtn" is not found, Selenium throws NoSuchElementException at runtime during the click attempt.
  3. Final Answer:

    A NoSuchElementException is thrown at runtime. -> Option A
  4. Quick Check:

    Missing element causes NoSuchElementException [OK]
Quick Trick: Missing element triggers NoSuchElementException on action [OK]
Common Mistakes:
  • Expecting NullPointerException instead
  • Thinking click silently fails
  • Assuming compile-time error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes