elements / checkbox
Single UI element
Checkbox & Radio
A single toggle, a checkbox group, an indeterminate parent/child hierarchy, and mutually exclusive radio buttons.
Single checkbox
#chk-single- id
- chk-single
- expected
- Toggles checked/unchecked, unchecked by default.
Code snippets
Python (Selenium)
chk = driver.find_element(By.ID, "chk-single")
if not chk.is_selected():
chk.click()
assert chk.is_selected()TypeScript (Playwright)
await page.check('#chk-single');
expect(await page.isChecked('#chk-single')).toBeTruthy();Checkbox group
#chk-group- ids
- chk-opt-1, chk-opt-2, chk-opt-3
- expected
- Independent toggles; SMS is checked by default.
Code snippets
Python (Selenium)
driver.find_element(By.ID, "chk-opt-1").click()
sms = driver.find_element(By.ID, "chk-opt-2")
assert sms.is_selected()TypeScript (Playwright)
await page.check('#chk-opt-1');
expect(await page.isChecked('#chk-opt-2')).toBeTruthy();Indeterminate parent
#chk-parent- id
- chk-parent
- children
- chk-child-1..3
- expected
- Parent becomes indeterminate when some (not all) children are checked; checking parent selects all children.
Code snippets
Python (Selenium)
# Check 1 child, check indeterminate property on parent
driver.find_element(By.ID, "chk-child-1").click()
is_indet = driver.execute_script("return document.getElementById('chk-parent').indeterminate;")
assert is_indetTypeScript (Playwright)
await page.check('#chk-child-1');
const isIndet: boolean = await page.evaluate(
() => (document.getElementById('chk-parent') as HTMLInputElement).indeterminate
);
expect(isIndet).toBeTruthy();Radio button group
#radio-plan- name
- pricing-plan
- ids
- radio-plan-free, radio-plan-pro, radio-plan-ent
- expected
- Only one radio option can be selected at a time within the same group name.
Code snippets
Python (Selenium)
driver.find_element(By.ID, "radio-plan-pro").click()
assert not driver.find_element(By.ID, "radio-plan-free").is_selected()
assert driver.find_element(By.ID, "radio-plan-pro").is_selected()TypeScript (Playwright)
await page.check('#radio-plan-pro');
expect(await page.isChecked('#radio-plan-pro')).toBeTruthy();
expect(await page.isChecked('#radio-plan-free')).toBeFalsy();