0
0
Selenium Javatesting~10 mins

Why POM creates maintainable test code in Selenium Java - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a Page Object class for the login page.

Selenium Java
public class LoginPage {
    private WebDriver driver;

    public LoginPage(WebDriver [1]) {
        this.driver = driver;
    }
}
Drag options to blanks, or click blank then click option'
Adriver
Bpage
CwebDriver
Dbrowser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name causes the driver field to remain null.
2fill in blank
medium

Complete the code to locate the username input field using a best practice locator.

Selenium Java
private By usernameField = By.[1]("username");
Drag options to blanks, or click blank then click option'
AclassName
Bid
CcssSelector
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using xpath unnecessarily makes tests slower and harder to maintain.
3fill in blank
hard

Fix the error in the method that enters the username text.

Selenium Java
public void enterUsername(String username) {
    driver.findElement(usernameField).[1](username);
}
Drag options to blanks, or click blank then click option'
Aclick
BgetText
CsendKeys
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of sendKeys does not enter text.
4fill in blank
hard

Fill both blanks to create a method that clicks the login button and waits for the home page.

Selenium Java
public void clickLogin() {
    driver.findElement([1]).click();
    new WebDriverWait(driver, Duration.ofSeconds(10))
        .until(ExpectedConditions.[2](By.id("homePage")));
}
Drag options to blanks, or click blank then click option'
AloginButton
BvisibilityOfElementLocated
Cclickable
DsubmitButton
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong locator names or waiting conditions causes test failures.
5fill in blank
hard

Fill in the blank to define a Page Object method that returns the page title after login.

Selenium Java
public String getPageTitle() {
    return driver.[1]();
}
Drag options to blanks, or click blank then click option'
AswitchTo
BgetWindowHandle
CpageTitle
DgetTitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using getWindowHandle returns a window handle, not the title.
switchTo() is for changing driver context, not retrieving the title.