0
0
Selenium Javatesting~10 mins

findElements for multiple matches 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 find all elements with the class name "item".

Selenium Java
List<WebElement> elements = driver.findElements(By.[1]("item"));
Drag options to blanks, or click blank then click option'
AclassName
Bid
Cname
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id instead of By.className
Using findElement instead of findElements
2fill in blank
medium

Complete the code to check if any elements with the tag name "button" exist.

Selenium Java
if (!driver.findElements(By.[1]("button")).isEmpty()) {
    System.out.println("Buttons found");
}
Drag options to blanks, or click blank then click option'
Aid
Bxpath
CcssSelector
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.cssSelector incorrectly
Not checking if the list is empty before using it
3fill in blank
hard

Fix the error in the code to correctly find all elements with the CSS selector ".active".

Selenium Java
List<WebElement> activeElements = driver.[1](By.cssSelector(".active"));
Drag options to blanks, or click blank then click option'
AfindElement
BfindElements
CfindAll
DfindBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using findElement instead of findElements
Using non-existent methods like findAll or findBy
4fill in blank
hard

Fill both blanks to create a list of elements with the name "option" and check if the list is empty.

Selenium Java
List<WebElement> options = driver.[1](By.[2]("option"));
if (options.isEmpty()) {
    System.out.println("No options found");
}
Drag options to blanks, or click blank then click option'
AfindElements
BfindElement
Cname
DclassName
Attempts:
3 left
💡 Hint
Common Mistakes
Using findElement instead of findElements
Using By.className instead of By.name
5fill in blank
hard

Fill all three blanks to find all elements with the CSS class "menu-item", get their count, and print it.

Selenium Java
List<WebElement> items = driver.[1](By.[2]("menu-item"));
int count = items.[3]();
System.out.println("Found " + count + " menu items.");
Drag options to blanks, or click blank then click option'
AfindElements
Bsize
CclassName
DfindElement
Attempts:
3 left
💡 Hint
Common Mistakes
Using findElement instead of findElements
Using By.id instead of By.className
Using length instead of size() for list size