Consider the following Selenium Java code that checks a checkbox and prints its status. What will be printed?
WebElement checkbox = driver.findElement(By.id("subscribe"));
checkbox.click();
System.out.println(checkbox.isSelected());Clicking a checkbox toggles its selection state.
After clicking the checkbox, it becomes selected, so isSelected() returns true.
You want to assert that a checkbox with id "terms" is not selected. Which assertion is correct?
Use assertFalse to check something is false.
isSelected() returns false if the checkbox is unchecked, so assertFalse is correct.
You want to locate a checkbox input that has a label with text "Accept". Which locator is best practice?
Labels often use the for attribute to link to checkbox id.
Option D uses XPath to find the checkbox whose id matches the for attribute of the label with text "Accept". This is the best practice for accessibility.
Given this code snippet, clicking the checkbox throws ElementNotInteractableException. Why?
WebElement checkbox = driver.findElement(By.id("newsletter"));
checkbox.click();ElementNotInteractableException means the element is present but not clickable.
This exception usually happens if the element is hidden or overlapped by another element, preventing interaction.
You have a list of checkbox elements. Which code snippet correctly asserts all are selected?
Use Java streams to check all elements satisfy a condition.
Option C uses allMatch to assert all checkboxes are selected in a clean and efficient way.