Radio Buttons
Radio button groups for testing single selection.
Selecting one option from a group
Radios are a group
Radio buttons with the same name form a group, and only one can be selected. Selecting one deselects the others. A good test asserts both.
const firefox = page.getByRole('radio', { name: 'Firefox' });
await firefox.check();
await expect(firefox).toBeChecked();
await expect(page.getByRole('radio', { name: 'Chrome' })).not.toBeChecked();You cannot uncheck a radio
A user can only deselect a radio by choosing another one, so Playwright's uncheck() throws an error on radio buttons. Select a different option instead.
Disabled options
await expect(page.getByRole('radio', { name: 'Internet Explorer' })).toBeDisabled();Select your browser
Selected browser: none
Next in Basic Elements · 5 of 6Dropdown →Choose options from native selects and from a custom dropdown.
Related exercises
- Basic ElementsBeginnerCheckboxesChange checkbox states and assert both the inputs and the state summary.
- FormsAdvancedMulti-step FormGet through a three-step sign-up, and test what happens between the steps.
- Content & AttributesIntermediateARIA WidgetsLocate widgets by their ARIA state, and assert whole structures with aria snapshots.
Read the guide: Playwright practice for beginners: a four-week plan