Challenge - 5 Problems
Page Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Page Object method?
Consider this Java Selenium Page Object method that returns the page title. What will be the output if the page title is "Welcome Page"?
Selenium Java
public class HomePage { private WebDriver driver; public HomePage(WebDriver driver) { this.driver = driver; } public String getPageTitle() { return driver.getTitle(); } } // Assume driver.getTitle() returns "Welcome Page"
Attempts:
2 left
💡 Hint
Think about what driver.getTitle() returns in Selenium.
✗ Incorrect
The getPageTitle() method calls driver.getTitle(), which returns the current page's title as a string. Since the page title is "Welcome Page", the method returns that exact string.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the presence of a button in a Page Object?
You have a Page Object with a method
isSubmitButtonDisplayed() that returns a boolean. Which assertion correctly checks that the submit button is visible?Selenium Java
public class LoginPage { private WebDriver driver; private By submitButton = By.id("submit"); public LoginPage(WebDriver driver) { this.driver = driver; } public boolean isSubmitButtonDisplayed() { return driver.findElement(submitButton).isDisplayed(); } }
Attempts:
2 left
💡 Hint
The method returns true if the button is visible.
✗ Incorrect
Since isSubmitButtonDisplayed() returns true when the button is visible, assertTrue verifies this condition correctly. Other assertions either check for false or null, which are incorrect here.
❓ locator
advanced2:00remaining
Which locator follows best practices for a Page Object element?
You want to locate a login input field in your Page Object. Which locator is best practice?
Attempts:
2 left
💡 Hint
Use the most specific and stable locator.
✗ Incorrect
By.id("loginInput") is the most specific and stable locator. XPath and CSS selectors shown are too generic and may select multiple elements. Class name may not be unique.
🔧 Debug
advanced2:00remaining
Why does this Page Object method throw NoSuchElementException?
This method tries to click a button but throws NoSuchElementException. What is the likely cause?
Selenium Java
public void clickLogin() {
driver.findElement(By.id("loginBtn")).click();
}Attempts:
2 left
💡 Hint
NoSuchElementException means Selenium cannot find the element.
✗ Incorrect
NoSuchElementException occurs when the element is not found in the current page DOM. This usually means the element is missing or the page is not fully loaded.
❓ framework
expert2:00remaining
What is the main benefit of using the Page Object Model in Selenium tests?
Choose the best explanation for why the Page Object Model (POM) is used in Selenium test automation.
Attempts:
2 left
💡 Hint
Think about how POM organizes code.
✗ Incorrect
POM organizes web page elements and actions into classes, separating them from test logic. This makes tests easier to maintain and read. It does not generate data, speed execution, or remove assertions.