0
0
Selenium Javatesting~10 mins

findElement by className 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 an element by its class name.

Selenium Java
WebElement element = driver.findElement(By.[1]("button-primary"));
Drag options to blanks, or click blank then click option'
Aid
Bname
CclassName
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'className' when searching by class.
Using 'name' or 'tagName' which locate differently.
2fill in blank
medium

Complete the code to click on the element found by class name.

Selenium Java
driver.findElement(By.className("submit-btn")).[1]();
Drag options to blanks, or click blank then click option'
AgetText
Bclick
CsendKeys
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'submit' instead of 'click' for clicking an element.
Trying to use 'getText' which only reads text.
3fill in blank
hard

Fix the error in the code to correctly find an element by class name.

Selenium Java
WebElement element = driver.findElement(By.[1]("main-content"));
Drag options to blanks, or click blank then click option'
AclassName
Bclass
Cclass_name
Dclassname
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'classname' which is not recognized.
Using underscores or other invalid method names.
4fill in blank
hard

Fill both blanks to find an element by class name and get its text.

Selenium Java
String text = driver.findElement(By.[1]("header-title")).[2]();
Drag options to blanks, or click blank then click option'
AclassName
BgetText
Cclick
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'getText' to read text.
Using 'id' instead of 'className' to locate by class.
5fill in blank
hard

Fill all three blanks to find an element by class name, check if it is displayed, and print the result.

Selenium Java
WebElement element = driver.findElement(By.[1]("nav-menu"));
boolean visible = element.[2]();
System.out.println("Is visible: " + [3]);
Drag options to blanks, or click blank then click option'
AclassName
BisDisplayed
Cvisible
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'isDisplayed' for visibility check.
Printing the method call instead of the variable.