0
0
Selenium Javatesting~10 mins

Why browser control drives test flow in Selenium Java - Test Your Understanding

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

Complete the code to open a browser and navigate to a URL.

Selenium Java
WebDriver driver = new ChromeDriver();
driver.[1]("https://example.com");
Drag options to blanks, or click blank then click option'
Aget
Bnavigate
Copen
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' instead of 'get' causes compilation errors.
2fill in blank
medium

Complete the code to find a button by its ID and click it.

Selenium Java
WebElement button = driver.findElement(By.[1]("submitBtn"));
button.click();
Drag options to blanks, or click blank then click option'
Aname
BclassName
Cid
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'className' when the element has an ID.
3fill in blank
hard

Fix the error in the code to wait until an element is visible before clicking.

Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.[1](By.id("loginBtn")));
driver.findElement(By.id("loginBtn")).click();
Drag options to blanks, or click blank then click option'
ApresenceOfElementLocated
BvisibilityOfElementLocated
CelementToBeClickable
DelementToBeSelected
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'presenceOfElementLocated' waits only for presence, not visibility.
4fill in blank
hard

Fill both blanks to correctly switch to a new browser tab and close it.

Selenium Java
String originalHandle = driver.getWindowHandle();
for (String handle : driver.[1]()) {
    if (!handle.equals(originalHandle)) {
        driver.[2](handle);
        driver.close();
    }
}
driver.switchTo().window(originalHandle);
Drag options to blanks, or click blank then click option'
AgetWindowHandles
BswitchTo
CswitchTo().window
DgetWindowHandle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getWindowHandle' instead of 'getWindowHandles' returns only one handle.
5fill in blank
hard

Fill all three blanks to create a test that opens a page, waits for a button, clicks it, and verifies the title.

Selenium Java
driver.[1]("https://example.com");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.[2](By.id("startBtn")));
driver.findElement(By.id("startBtn")).click();
assertEquals("Welcome Page", driver.[3]());
Drag options to blanks, or click blank then click option'
Aget
BvisibilityOfElementLocated
CgetTitle
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'get' to open the page.
Not waiting for visibility before clicking.