Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' instead of 'get' causes compilation errors.
✗ Incorrect
The get method loads a new web page in the current browser window.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'className' when the element has an ID.
✗ Incorrect
The By.id locator finds elements by their unique ID attribute.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
presenceOfElementLocated may cause errors if element is hidden.✗ Incorrect
visibilityOfElementLocated waits until the element is visible on the page.
4fill in blank
hardFill the blank to create a test that asserts the page title contains a word.
Selenium Java
String title = driver.getTitle(); assertTrue(title.[1]("Example"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equals' checks exact match, not containment.
✗ Incorrect
The contains method checks if the title includes the given word.
5fill in blank
hardFill both blanks to create a map of element texts filtered by length.
Selenium Java
Map<String, Integer> lengths = elements.stream() .filter(e -> e.getText().length() [1] 3) .collect(Collectors.toMap(e -> e.getText(), e -> e.getText().[2]())); lengths.forEach((k, v) -> System.out.println(k + ": " + v));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' without parentheses causes errors.
✗ Incorrect
The filter keeps texts longer than 3 characters. The map stores text and its length.