TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 41 of 60~18 min • Beginner
Chapter 41Playwright

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

  1. Create native controls
  2. Select a checkbox and option
  3. Verify both

Example

TypeScript
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');
});
Expected result: Checkbox checked; Pro selected
💡 Point to remember
Inspect whether a dropdown is native or custom before selecting it.

Practice application screenshot

Actual screenshot of the TestingDocs task manager practice application
TestingDocs practice page, captured in Chromium.

✎ Your practice task

Add a radio group and choose one option.

Knowledge check

Which API selects a native dropdown option?

🌐 Continue learning