Complete the code to declare a Page Object class for the login page.
public class LoginPage { private WebDriver driver; public LoginPage(WebDriver [1]) { this.driver = driver; } }
The constructor parameter should be named driver to assign it correctly to the class field.
Complete the code to locate the username input field using a best practice locator.
private By usernameField = By.[1]("username");
Using By.id is the best practice locator when the element has a unique id attribute.
Fix the error in the method that enters the username text.
public void enterUsername(String username) {
driver.findElement(usernameField).[1](username);
}click instead of sendKeys does not enter text.The sendKeys method types text into input fields.
Fill both blanks to create a method that clicks the login button and waits for the home page.
public void clickLogin() {
driver.findElement([1]).click();
new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.[2](By.id("homePage")));
}The method clicks the login button and waits until the home page element is visible.
Fill in the blank to define a Page Object method that returns the page title after login.
public String getPageTitle() {
return driver.[1]();
}
getWindowHandle returns a window handle, not the title.switchTo() is for changing driver context, not retrieving the title.The getTitle() method on WebDriver returns the title of the current page. No locator or switching is needed.