0
0
Selenium Javatesting~20 mins

Page class design in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Page Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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"
A"Welcome Page"
B"homepage"
Cnull
DThrows NoSuchElementException
Attempts:
2 left
💡 Hint
Think about what driver.getTitle() returns in Selenium.
assertion
intermediate
2: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();
    }
}
AassertTrue(loginPage.isSubmitButtonDisplayed());
BassertFalse(loginPage.isSubmitButtonDisplayed());
CassertNull(loginPage.isSubmitButtonDisplayed());
DassertEquals(loginPage.isSubmitButtonDisplayed(), false);
Attempts:
2 left
💡 Hint
The method returns true if the button is visible.
locator
advanced
2: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?
ABy.cssSelector("input")
BBy.xpath("//input[@type='text']")
CBy.id("loginInput")
DBy.className("input-field")
Attempts:
2 left
💡 Hint
Use the most specific and stable locator.
🔧 Debug
advanced
2: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();
}
AThe driver is not initialized properly.
BThe method should use findElements instead of findElement.
CThe click() method is deprecated and causes the exception.
DThe element with id "loginBtn" is not present or not yet loaded on the page.
Attempts:
2 left
💡 Hint
NoSuchElementException means Selenium cannot find the element.
framework
expert
2: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.
AIt automatically generates test data for form inputs.
BIt separates test code from page-specific code, improving maintainability and readability.
CIt speeds up test execution by running tests in parallel.
DIt replaces the need for assertions in test scripts.
Attempts:
2 left
💡 Hint
Think about how POM organizes code.