like in selenium, do we have option in Playwright to wait for an element to be clickable ?
For page.click(selector[, options]), Playwright will ensure that:
So, you can use this:
await page.click('button');
If you want to add a timeout, basically to allow playwright to complete the above checks and then click, you can do like this:
await page.click('button', {timeout: 9000});
To first check that the element is visible and then click another element based on the result, you can use an if-else like this:
if (await page.locator('modal-selector').isEnabled()) {
await page.click('button1')
} else {
//do something
}
Playwright is "auto-waiting" for this.
Checkout the documentation: https://playwright.dev/docs/actionability
You can check the button state with the method isDisabled()
Checkout the docs: https://playwright.dev/docs/api/class-elementhandle#element-handle-is-disabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With