Playwright Handle Checkbox and Radio Buttons

Playwright Handle Checkbox and Radio Buttons

The playwright can check the checkboxes using the check() and uncheck() command to uncheck a checkbox.

Let us check it out in action.

playwright dropdown checkboxes

  • Here is the page we will uncheck the first checkbox and check everything else from the radio button countries India and windows will be selected, and the third checkbox will be asserted whether it is checked.
const {test, expect} = require('@playwright/test');
test('Checkbox And RadioButton', async ({page})=> 
{

await page.goto("http://autopract.com/selenium/form5/");
await page.locator("input[value='one']").uncheck()
await page.locator("input[value='two']").check()
await page.locator("input[value='three']").check()
expect(await page.isChecked("input[value='three']")).toBeTruthy
await page.locator("input[value='four']").check()
await page.locator("input[value='IN']").check()
await page.locator("input[value='windows']").check()

});

  • We can see it has checked the boxes matching our requirement and asserted the third checkbox using the isChecked().
Tags
Standard (Image)