Bird
0
0

You need to select multiple checkboxes on a page where all checkboxes share the class name "optionCheck". Which code snippet correctly selects all unchecked checkboxes?

hard📝 Application Q8 of 15
Selenium Java - Handling Form Elements
You need to select multiple checkboxes on a page where all checkboxes share the class name "optionCheck". Which code snippet correctly selects all unchecked checkboxes?
AList<WebElement> boxes = driver.findElements(By.className("optionCheck")); for (WebElement box : boxes) { if (!box.isSelected()) { box.click(); } }
BWebElement box = driver.findElement(By.className("optionCheck")); if (!box.isSelected()) { box.click(); }
CList<WebElement> boxes = driver.findElements(By.className("optionCheck")); for (WebElement box : boxes) { box.click(); }
Ddriver.findElement(By.className("optionCheck")).click();
Step-by-Step Solution
Solution:
  1. Step 1: Find all checkboxes by class name

    Use findElements to get a list of all checkboxes with class "optionCheck".
  2. Step 2: Loop and click only unchecked boxes

    Iterate over each checkbox, check if it is not selected, then click to select.
  3. Final Answer:

    Code snippet that loops over all checkboxes and clicks unchecked ones -> Option A
  4. Quick Check:

    Loop + check isSelected() + click unchecked [OK]
Quick Trick: Loop through all checkboxes, click only if not selected [OK]
Common Mistakes:
MISTAKES
  • Using findElement instead of findElements for multiple elements
  • Clicking all checkboxes without checking state
  • Not looping through all checkboxes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes