0
0
Selenium Javatesting~10 mins

Checkbox 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 find a checkbox by its ID.

Selenium Java
WebElement checkbox = driver.findElement(By.[1]("subscribeCheckbox"));
Drag options to blanks, or click blank then click option'
Aid
BclassName
Cname
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name or By.className when the element has a unique ID.
Using By.tagName which selects by tag, not ID.
2fill in blank
medium

Complete the code to check if the checkbox is selected.

Selenium Java
boolean isChecked = checkbox.[1]();
Drag options to blanks, or click blank then click option'
AisSelected
BisDisplayed
CisEnabled
DisChecked
Attempts:
3 left
💡 Hint
Common Mistakes
Using isDisplayed() which checks visibility, not selection.
Using isEnabled() which checks if the element is enabled.
3fill in blank
hard

Fix the error in the code to click the checkbox only if it is not already selected.

Selenium Java
if (!checkbox.[1]()) {
    checkbox.click();
}
Drag options to blanks, or click blank then click option'
AisDisplayed
BisChecked
CisSelected
DisEnabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using isDisplayed() which checks visibility, not selection.
Using isEnabled() which checks if the element is enabled.
4fill in blank
hard

Fill both blanks to find a checkbox by its name and click it if it is not selected.

Selenium Java
WebElement checkbox = driver.findElement(By.[1]("agreeTerms"));
if (!checkbox.[2]()) {
    checkbox.click();
}
Drag options to blanks, or click blank then click option'
Aname
BisSelected
Cid
DisEnabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using id instead of name when the element is identified by name.
Using isEnabled() instead of isSelected() to check selection.
5fill in blank
hard

Fill all three blanks to find a checkbox by CSS selector, verify it is enabled, and then click it if not selected.

Selenium Java
WebElement checkbox = driver.findElement(By.[1]("input[type='checkbox'][name='newsletter']"));
if (checkbox.[2]() && !checkbox.[3]()) {
    checkbox.click();
}
Drag options to blanks, or click blank then click option'
AcssSelector
BisEnabled
CisSelected
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using id instead of cssSelector for complex selectors.
Checking isSelected() before isEnabled() which may cause errors.
Using wrong method names like isChecked() which does not exist.