Skip to main content

Overview

The CheckboxElement class is a Playwright wrapper for the <vaadin-checkbox> component. It provides methods to interact with checkboxes, including checking/unchecking and managing indeterminate state.

Component Tag

<vaadin-checkbox>

Extends

  • VaadinElement

Implements

  • FocusableElement - Focus and blur operations
  • HasAriaLabelElement - ARIA label support
  • HasEnabledElement - Enabled/disabled state
  • HasHelperElement - Helper text
  • HasValueElement - Value handling
  • HasStyleElement - CSS styling
  • HasLabelElement - Label text
  • HasValidationPropertiesElement - Validation state and error messages

Constructor

locator
Locator
required
The Playwright locator for the <vaadin-checkbox> element
public CheckboxElement(Locator locator)

Factory Methods

getByLabel

Get a checkbox by its accessible label. Uses ARIA role checkbox.
page
Page
required
The Playwright page
label
String
required
The accessible label of the checkbox
public static CheckboxElement getByLabel(Page page, String label)

Example

CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Accept Terms");
checkbox.check();
checkbox.assertChecked();

Methods

isChecked

Check if the checkbox is currently checked.
public boolean isChecked()
Returns: true if checked, false otherwise

assertChecked

Assert that the checkbox is checked.
public void assertChecked()

assertNotChecked

Assert that the checkbox is not checked.
public void assertNotChecked()

Example

CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Default Checkbox");
checkbox.assertNotChecked();
checkbox.check();
checkbox.assertChecked();

check

Check the checkbox.
public void check()

uncheck

Uncheck the checkbox.
public void uncheck()

Example

CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Default Checkbox");
checkbox.check();
checkbox.assertChecked();
checkbox.uncheck();
checkbox.assertNotChecked();

isIndeterminate

Check if the checkbox is in indeterminate state.
public boolean isIndeterminate()
Returns: true when indeterminate, false otherwise

assertIndeterminate

Assert that the checkbox is indeterminate.
public void assertIndeterminate()

assertNotIndeterminate

Assert that the checkbox is not indeterminate.
public void assertNotIndeterminate()

setIndeterminate

Set the indeterminate state.
indeterminate
boolean
required
true to set indeterminate, false to clear
public void setIndeterminate(boolean indeterminate)

Example

CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Indeterminate Checkbox");
checkbox.assertIndeterminate();
checkbox.check();
checkbox.assertNotIndeterminate();
checkbox.assertChecked();

getEnabledLocator

Get the locator for enabled/disabled state. Returns the input locator.
public Locator getEnabledLocator()

getAriaLabelLocator

Get the locator for ARIA label operations. Returns the input locator.
public Locator getAriaLabelLocator()

getFocusLocator

Get the locator for focus operations. Returns the input locator.
public Locator getFocusLocator()

Inherited Methods

From HasValueElement:
  • getValue() - Get current value
  • setValue(String value) - Set field value
  • clear() - Clear the value
  • assertValue(String value) - Assert value matches
  • getInputLocator() - Get input element locator
From HasValidationPropertiesElement:
  • assertValid() - Assert checkbox is valid
  • assertInvalid() - Assert checkbox is invalid
  • assertErrorMessage(String message) - Assert error message text
  • getErrorMessageLocator() - Get error message locator
From HasLabelElement:
  • getLabel() - Get label text
  • assertLabel(String label) - Assert label text
  • getLabelLocator() - Get label locator
From HasHelperElement:
  • getHelperText() - Get helper text
  • assertHelperHasText(String text) - Assert helper text
  • getHelperLocator() - Get helper locator
From FocusableElement:
  • focus() - Focus the checkbox
  • blur() - Blur the checkbox
  • getTabIndex() - Get tab index
  • assertIsFocused() - Assert checkbox has focus
  • assertIsNotFocused() - Assert checkbox does not have focus
From HasEnabledElement:
  • assertEnabled() - Assert checkbox is enabled
  • assertDisabled() - Assert checkbox is disabled
From HasAriaLabelElement:
  • assertAriaLabel(String label) - Assert ARIA label

Complete Example

@Test
public void testBasicCheckbox() {
    // Find checkbox by label
    CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Default Checkbox");
    checkbox.assertVisible();
    checkbox.assertNotChecked();
    checkbox.assertEnabled();
    
    // Check and uncheck
    checkbox.check();
    checkbox.assertChecked();
    checkbox.uncheck();
    checkbox.assertNotChecked();
}

@Test
public void testIndeterminateCheckbox() {
    CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Indeterminate Checkbox");
    checkbox.assertVisible();
    checkbox.assertIndeterminate();
    
    // Clicking changes state
    checkbox.check();
    checkbox.assertNotIndeterminate();
    checkbox.assertChecked();
}

@Test
public void testCheckboxValidation() {
    CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Required Checkbox");
    checkbox.assertValid();
    
    // Check and uncheck required checkbox
    checkbox.check();
    checkbox.assertValid();
    
    checkbox.uncheck();
    checkbox.assertInvalid();
    checkbox.assertErrorMessage("Required Message");
}

@Test
public void testDisabledCheckbox() {
    CheckboxElement checkbox = CheckboxElement.getByLabel(page, "Disabled Checkbox");
    checkbox.assertVisible();
    checkbox.assertDisabled();
}

Build docs developers (and LLMs) love