Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Find the checkboxes inside the intended form or container, then check each element’s selected state and click only when it is unchecked. A checkbox click toggles its state, so blindly clicking every match can turn already-selected boxes off. The examples below show how to scope the locator, handle pages that render controls asynchronously, and verify the result.

Use a state-aware loop

Checkboxes are independent controls: to select several, locate the intended checkbox inputs and operate on each one. In Python, Selenium’s find_elements returns the matching elements, is_selected() reports whether a checkbox is selected, and click() changes its state.

from selenium.webdriver.common.by import By

boxes = driver.find_elements(
    By.CSS_SELECTOR,
    "#preferences input[type='checkbox']"
)

for box in boxes:
    if not box.is_selected():
        box.click()

Replace #preferences with a stable selector for the actual form, fieldset, or container. The loop makes the requested end state explicit: every matching checkbox should be selected. If you run it again, it leaves selected boxes alone instead of toggling them off.

Use a narrow locator. A page-wide selector such as input[type='checkbox'] may include unrelated options, such as settings outside the form you meant to change. Scope the selector to the relevant group before acting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a locator for the right group

Start with the page’s markup and identify a stable way to target both the group and its checkbox inputs. An ID, a meaningful name, or a CSS selector tied to a form or container is usually easier to maintain than a positional XPath that depends on where an element happens to appear.

  • Scope first: use a distinctive container selector, then target checkbox inputs within it.
  • Confirm the element type: include input[type='checkbox'] when appropriate so the locator does not accidentally match a label or a different input.
  • Avoid broad page-wide actions: only remove the container scope if selecting every checkbox on the page is genuinely the goal.
  • Check the matches: if the locator finds no elements or too many, inspect the page structure and refine it before clicking.

The example selector is illustrative, not a universal locator. Sites differ in their markup, and a selector that works on one page may not match another.

Wait for asynchronously rendered controls

If a page adds its checkboxes after navigation, an immediate lookup may run before the controls exist. Wait for the relevant elements to be present before looping through them. For example, Python’s explicit wait can wait for all elements matching a locator:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

locator = (By.CSS_SELECTOR, "#preferences input[type='checkbox']")
boxes = WebDriverWait(driver, 10).until(
    EC.presence_of_all_elements_located(locator)
)

for box in boxes:
    if not box.is_selected():
        box.click()

Here, 10 is the maximum wait in seconds for this example, not a guarantee that every page will load within that time. Choose a limit suitable for your application and wait for the condition the next action actually requires. Presence means the elements have been found; if the page still has to finish making them interactable, wait for that state as well.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A fixed sleep pauses for the same duration regardless of whether the controls are ready sooner or later. Prefer waiting for a relevant condition, then handle a timeout as a page or test failure rather than proceeding as if the controls were present.

Java example

The same state-checking pattern works in Java. This method accepts an existing WebDriver and selects all checkbox inputs found within the specified container:

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public static void selectCheckboxes(WebDriver driver) {
    List<WebElement> boxes = driver.findElements(
        By.cssSelector("#preferences input[type='checkbox']")
    );

    for (WebElement box : boxes) {
        if (!box.isSelected()) {
            box.click();
        }
    }
}

Change the container selector to match your page. The method assumes the driver has already reached the relevant page and that the locator finds the intended controls. Selenium’s Java method is isSelected(); in Python the corresponding method is is_selected().

Verify the selection

Do not treat the absence of an exception as proof that the form now has the intended state. After clicking, check each element again:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
not_selected = [box for box in boxes if not box.is_selected()]

if not_selected:
    raise AssertionError(
        f"{len(not_selected)} checkbox(es) remain unchecked"
    )

This verifies the checkbox state reported by WebDriver. If the application updates a separate result, summary, or submit state, wait for and verify that application behavior too; a checked control and a completed form action are not necessarily the same condition.

For a test that should select only a subset, define that subset with the locator or a condition based on the page’s data, then apply the same state-aware click rule to those matches. Do not click the other boxes merely to “clear” them unless clearing them is part of the intended outcome; clicking toggles them too.

When the checkbox is custom-styled

Some pages display a custom checkbox while hiding the native input. Inspect the markup and determine which element is actually intended to receive user interaction. A hidden input may not accept a normal Selenium click. The visible label or custom widget may be the interactable target, but verify the resulting state through the checkbox input or the application’s accessible state rather than assuming the visual change succeeded.

Selenium checks whether an element can be interacted with. If the target is hidden, disabled, or obstructed, the click may fail instead of behaving like a user action. Prefer locating the page’s real interactable control and checking its state after the click; do not treat JavaScript that forces a state change as equivalent to an ordinary WebDriver interaction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • No elements found: the selector may not match the page, the group may be rendered later, or the page may not be at the expected state. Inspect the markup and wait for the relevant controls before retrying.
  • Element not interactable: the matched input may be hidden or otherwise unavailable for a normal click. Locate the visible, interactable control associated with the checkbox and verify the input’s resulting state.
  • Element click intercepted: an overlay or another element may obscure the checkbox’s center point. Check for banners, dialogs, animation, or other obstructions; wait for them to finish or use the appropriate visible target. Selenium documents an intercepted-click error when an element’s center is obscured.
  • Some boxes remain unchecked: the page may update its controls during the loop, or a click may not have taken effect. Re-read each selected state and investigate the specific controls that failed rather than assuming the initial collection reflects the final state.
  • A rerun reverses the result: the code probably clicks every match without checking state first. Use the state-aware loop so already-selected boxes are not toggled off.
  • The wrong options changed: the locator is too broad. Scope it to the intended form or group and verify the matches before interacting.

When diagnosing a failed interaction, consider visibility, enabled state, scrolling, overlays, and animation. Selenium’s interaction behavior is based on whether the target can be interacted with; a successful lookup alone does not establish that a click can succeed.

Checkboxes are not multi-select dropdowns

A group of checkbox inputs and a dropdown built as <select multiple> are different controls. The checkbox loop operates on individual checkboxes. Selenium’s select-list support is for a <select> element, not an arbitrary group of checkbox inputs. Identify the HTML control before choosing an interaction method.

Performance and reliability

For a normal form-sized group, locating the matching checkboxes once and iterating over the returned elements is straightforward. Reliability depends more on selecting the right group and interacting at the right time than on using a more elaborate loop. Avoid repeatedly searching the whole page for each checkbox when a single scoped lookup provides the group you need.

Pages can change while a test is running. If an interaction causes the form to rerender, an element reference collected earlier may no longer represent the current control. In that case, wait for the page’s update, locate the current controls again, and verify their state. Do not add arbitrary retries that click regardless of state: because a checkbox is a toggle, such retries can undo a successful selection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your goal is to capture a page rather than automate its checkbox controls, ScreenshotNeo can return a screenshot or PDF from one GET request. It does not select checkboxes or replace Selenium for form interaction. Its API accepts a URL and can return PNG, JPEG, WebP, or PDF; see the ScreenshotNeo documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes known cookie-consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also provides an MCP server with screenshot, page-info, and PDF-capture tools for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.