To click on a button with text "foo" in @playwright/test, follow these steps:
getByText()
method.click()
method to perform a simple human click.Here's an example code snippet:
await page.getByText('foo').click();
If you need to perform a double-click or right-click instead of a simple click, use the dblclick()
method for double-click and pass { button: 'right' }
as an option to click()
for right-click.
Sometimes, apps may use non-trivial logic where hovering over an element overlays it with another element that intercepts the click. If this causes issues with your test, bypass actionability checks and force the click by passing { force: true }
as an option to click()
. However, use this only when necessary.
With these methods, you can easily click on a button with text "foo" using @playwright/test.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].