Bird
0
0

Given the following page class snippet, what will be the output of loginPage.getLoginButtonText() if the button text is "Sign In"?

medium📝 Predict Output Q4 of 15
Selenium Java - Page Object Model
Given the following page class snippet, what will be the output of loginPage.getLoginButtonText() if the button text is "Sign In"?
public class LoginPage {
  @FindBy(id = "loginBtn")
  private WebElement loginButton;

  public String getLoginButtonText() {
    return loginButton.getText();
  }
}
Anull
B"Sign In"
CloginBtn
DThrows NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand getText() behavior

    The getText() method returns the visible text of the WebElement, which is "Sign In" here.
  2. Step 2: Consider element presence

    If the element is present and located correctly, getText() returns the button text. No exception occurs.
  3. Final Answer:

    "Sign In" -> Option B
  4. Quick Check:

    getText() returns visible text = "Sign In" [OK]
Quick Trick: getText() returns visible text of element [OK]
Common Mistakes:
  • Expecting locator id as text
  • Assuming null if text exists
  • Ignoring element presence causing exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes