Search code examples
javascripttypescriptcheckboxplaywright

check() vs setChecked(true) playwright


I'm trying to understand what is the difference between locator.check and locator.setChecked when it set to true.

I've checked the docs and it looks like they're basically the same.

I've checked their functionality and it seems like they do the same.

Is there any difference? maybe a different purpose?


Solution

  • locator.check

    enter image description here

    locator.setCheck

    enter image description here

    So, judging by the documentation, locator.check will throw if the element is detached from DOM at any moment during action, whereas locator.setCheck will retry in that scenario.