0
0
Selenium Javatesting~10 mins

Base page class pattern in Selenium Java - Interactive Code Practice

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

Complete the code to declare the WebDriver variable in the base page class.

Selenium Java
public class BasePage {
    protected WebDriver [1];

    public BasePage(WebDriver driver) {
        this.driver = driver;
    }
}
Drag options to blanks, or click blank then click option'
Adriver
Bbrowser
CwebDriver
Dwd
Attempts:
3 left
💡 Hint
Common Mistakes
Using uncommon or unclear variable names like 'browser' or 'wd'.
2fill in blank
medium

Complete the constructor to assign the passed WebDriver to the class variable.

Selenium Java
public BasePage(WebDriver driver) {
    this.[1] = driver;
}
Drag options to blanks, or click blank then click option'
Adriver
Bwd
CwebDriver
Dbrowser
Attempts:
3 left
💡 Hint
Common Mistakes
Using the parameter name without 'this.' which causes shadowing.
3fill in blank
hard

Fix the error in the method to find an element by its ID.

Selenium Java
public WebElement findElementById(String id) {
    return driver.findElement(By.[1](id));
}
Drag options to blanks, or click blank then click option'
Axpath
Bname
CclassName
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong locator methods like 'name' or 'className' when searching by ID.
4fill in blank
hard

Fill both blanks to create a method that waits until an element is visible by its CSS selector.

Selenium Java
public WebElement waitForElementVisible(String cssSelector) {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([1]));
    return wait.until(ExpectedConditions.[2](By.cssSelector(cssSelector)));
}
Drag options to blanks, or click blank then click option'
A10
BvisibilityOfElementLocated
CpresenceOfElementLocated
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using too short wait times or wrong ExpectedConditions like presenceOfElementLocated.
5fill in blank
hard

Fill all three blanks to create a method that clicks an element after waiting for it to be clickable by XPath.

Selenium Java
public void clickWhenClickable(String xpath) {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([1]));
    WebElement element = wait.until(ExpectedConditions.[2](By.[3](xpath)));
    element.click();
}
Drag options to blanks, or click blank then click option'
A15
BelementToBeClickable
Cxpath
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong wait times or locator methods, or wrong ExpectedConditions.