0
0
Selenium Javatesting~10 mins

Utility classes 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 create a WebDriver instance using a utility class method.

Selenium Java
WebDriver driver = UtilityClass.[1]();
Drag options to blanks, or click blank then click option'
AinitializeDriver
BstartSession
ClaunchBrowser
DgetDriver
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not exist in the utility class.
Confusing method names that start a session but do not return the driver.
2fill in blank
medium

Complete the code to wait for an element to be visible using the utility class.

Selenium Java
UtilityClass.[1](driver, By.id("submitBtn"), 10);
Drag options to blanks, or click blank then click option'
AwaitForVisibility
BwaitForPresence
CwaitForClickable
DwaitForText
Attempts:
3 left
💡 Hint
Common Mistakes
Using waitForClickable when visibility is required.
Using waitForPresence which waits only for the element to be in the DOM.
3fill in blank
hard

Fix the error in the utility method call to take a screenshot.

Selenium Java
UtilityClass.[1](driver, "error.png");
Drag options to blanks, or click blank then click option'
AtakeScreenshot
BcaptureScreenshot
CcaptureScreen
DtakeScreenShot
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization in method names.
Using similar but non-existent method names.
4fill in blank
hard

Fill both blanks to create a utility method that returns a list of WebElements by CSS selector.

Selenium Java
public static List<WebElement> [1](WebDriver driver, String selector) {
    return driver.findElements(By.[2](selector));
}
Drag options to blanks, or click blank then click option'
AgetElementsByCss
BgetElementsById
CcssSelector
DclassName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.className instead of By.cssSelector.
Using method names that do not describe CSS selection.
5fill in blank
hard

Fill all three blanks to implement a utility method that waits for an element to be clickable and then clicks it.

Selenium Java
public static void [1](WebDriver driver, By locator, int timeout) {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([2]));
    WebElement element = wait.until(ExpectedConditions.[3](locator));
    element.click();
}
Drag options to blanks, or click blank then click option'
AclickWhenReady
Btimeout
CelementToBeClickable
DwaitTime
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong ExpectedConditions methods like visibility instead of clickability.
Using incorrect variable names for timeout.