0
0
Selenium Javatesting~10 mins

Auto-complete field handling 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 locate the auto-complete input field by its ID.

Selenium Java
WebElement input = driver.findElement(By.[1]("searchBox"));
Drag options to blanks, or click blank then click option'
AclassName
BtagName
Cid
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name or By.className when the element has a unique ID.
Using By.tagName which is too broad and may select multiple elements.
2fill in blank
medium

Complete the code to send the text 'Selenium' to the auto-complete input field.

Selenium Java
input.[1]("Selenium");
Drag options to blanks, or click blank then click option'
AsendKeys
Bclear
Cclick
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of sendKeys() to enter text.
Using clear() which only clears the field but does not enter text.
3fill in blank
hard

Fix the error in the code to wait until the auto-complete suggestions are visible.

Selenium Java
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.[1](By.className("suggestions")));
Drag options to blanks, or click blank then click option'
AinvisibilityOfElementLocated
BpresenceOfElementLocated
CelementToBeClickable
DvisibilityOfElementLocated
Attempts:
3 left
💡 Hint
Common Mistakes
Using invisibilityOfElementLocated which waits for element to disappear.
Using presenceOfElementLocated which may not guarantee visibility.
4fill in blank
hard

Fill both blanks to select the first suggestion from the auto-complete list.

Selenium Java
List<WebElement> suggestions = driver.findElements(By.[1]("suggestion-item"));
suggestions.get([2]).click();
Drag options to blanks, or click blank then click option'
AclassName
Bid
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using id instead of className when suggestions have a class.
Using index 1 which selects the second suggestion instead of the first.
5fill in blank
hard

Fill all three blanks to verify the selected suggestion text matches 'Selenium WebDriver'.

Selenium Java
String selectedText = suggestions.get([1]).getText();
assertEquals([2], selectedText, "Suggestion text should be correct");
System.out.println("Selected: " + [3]);
Drag options to blanks, or click blank then click option'
A0
B"Selenium WebDriver"
CselectedText
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 which selects the wrong suggestion.
Mixing up expected and actual parameters in assertEquals.
Printing the expected string instead of the selected text variable.