Chapter 41: Checkboxes, radio buttons and dropdowns
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Checkboxes, radio buttons and dropdowns
check selects a checkbox or radio input and uncheck clears a checkbox. selectOption works with native select elements. Custom dropdowns usually need role-based clicks instead. Verify the final checked or selected state.
How it works
Step-by-step walkthrough
- Create native controls
- Select a checkbox and option
- Verify both
Example
import { test, expect } from '@playwright/test';
test('chapter 41 practice', async ({ page }) => {
await page.setContent('<label><input type="checkbox"> Agree</label><label>Plan <select><option value="basic">Basic</option><option value="pro">Pro</option></select></label>');
await page.getByLabel('Agree').check();
await page.getByLabel('Plan').selectOption('pro');
await expect(page.getByLabel('Agree')).toBeChecked();
await expect(page.getByLabel('Plan')).toHaveValue('pro');
});Inspect whether a dropdown is native or custom before selecting it.
Practice application screenshot
✎ Your practice task
Add a radio group and choose one option.
Knowledge check
Which API selects a native dropdown option?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.