Bird
0
0

Given the following Page Object method, what will be the output when calling loginPage.getTitle() if the page title is "Welcome Page"?

medium📝 Predict Output Q13 of 15
Selenium Java - Page Object Model
Given the following Page Object method, what will be the output when calling loginPage.getTitle() if the page title is "Welcome Page"?
public class LoginPage {
  WebDriver driver;
  public LoginPage(WebDriver driver) {
    this.driver = driver;
  }
  public String getTitle() {
    return driver.getTitle();
  }
}
A"Welcome Page"
B"Login Page"
Cnull
DThrows NullPointerException
Step-by-Step Solution
Solution:
  1. Step 1: Understand getTitle() method

    The method returns the title of the current page from the WebDriver.
  2. Step 2: Given page title is "Welcome Page"

    Calling getTitle() returns the actual page title string, which is "Welcome Page".
  3. Final Answer:

    "Welcome Page" -> Option A
  4. Quick Check:

    driver.getTitle() returns current page title [OK]
Quick Trick: driver.getTitle() returns the current page title string [OK]
Common Mistakes:
  • Confusing method return with page object name
  • Assuming method returns null or exception without driver
  • Thinking getTitle() returns page URL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes