Complete the code to declare a WebDriver variable in the page class.
private [1] driver;The WebDriver variable is declared as WebDriver type to control the browser.
Complete the constructor to initialize the WebDriver variable.
public LoginPage([1] driver) {
this.driver = driver;
}The constructor parameter must be of type WebDriver to assign it to the class variable.
Fix the error in the method to locate the username input field.
public WebElement getUsernameField() {
return driver.findElement([1]);
}Using By.id("username") is the most direct and reliable way to locate the username input field by its id attribute.
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 login button is located by By.id("loginBtn") and the wait condition is visibilityOfElementLocated to ensure the home page is visible after login.
Fill all three blanks to create a method that enters username and password, then clicks login.
public void login(String username, String password) {
driver.findElement([1]).sendKeys(username);
driver.findElement([2]).sendKeys(password);
driver.findElement([3]).click();
}The username and password fields are located by their ids "username" and "password", and the login button by "loginBtn".