Check and Uncheck Checkbox in Playwright Java

Profile picture for user arilio666

This article will show how to check and uncheck checkboxes in Playwright Using Java.

Using Click Method

We can check a checkbox using the click method present in playwright.

page.navigate("http://autopract.com/selenium/form5//");
page.locator("//input[@value='four']").click();

We can also uncheck the exact checkbox using the click() method again on the four checkbox.

Using the Check And Uncheck Method

We can use the method called to check, which is solely used to check checkboxes.

page.navigate("http://autopract.com/selenium/form5//");
page.locator("//input[@value='four']").check();

Using the uncheck method, we can easily uncheck the checked box.

page.navigate("http://autopract.com/selenium/form5//");
page.locator("//input[@value='four']").uncheck();