Complete the code to declare the WebDriver variable in the base page class.
public class BasePage { protected WebDriver [1]; public BasePage(WebDriver driver) { this.driver = driver; } }
The WebDriver variable is commonly named driver to keep code clear and consistent.
Complete the constructor to assign the passed WebDriver to the class variable.
public BasePage(WebDriver driver) {
this.[1] = driver;
}The constructor assigns the parameter driver to the class variable driver using this.driver = driver;.
Fix the error in the method to find an element by its ID.
public WebElement findElementById(String id) {
return driver.findElement(By.[1](id));
}To find an element by its ID, use By.id().
Fill both blanks to create a method that waits until an element is visible by its CSS selector.
public WebElement waitForElementVisible(String cssSelector) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([1]));
return wait.until(ExpectedConditions.[2](By.cssSelector(cssSelector)));
}The wait time is commonly set to 10 seconds, and visibilityOfElementLocated waits until the element is visible.
Fill all three blanks to create a method that clicks an element after waiting for it to be clickable by XPath.
public void clickWhenClickable(String xpath) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([1]));
WebElement element = wait.until(ExpectedConditions.[2](By.[3](xpath)));
element.click();
}We wait 10 seconds, use elementToBeClickable condition, and locate by By.xpath.