Rayrun
← Back to Discord Forum

locator.click target closed

locator.click: Target closed =========================== logs =========================== waiting for getByTestId('animate-bounce') locator resolved to <button type="button" class="animate-bounce" data-testid…>…</button> attempting click action waiting for element to be visible, enabled and stable element is not stable - waiting...

6 | await page.goto('https://dev.mymagic.com/'); 7 |

8 | await page.getByTestId('animate-bounce').click(); | ^ 9 |

This thread is trying to answer question "How to resolve the 'locator.click: Target closed' issue when trying to click on an animated or moving element?"

8 replies

From what it seems you are trying to click something that is animated or moving

try maybe the force click action if you really need to click it there

or look for another selector if you can replace it

suresh1051
suresh1051

@_godsown did you manage to find a fix for this?

Yes thanks @suresh1051

@_godsown can you please tell me what is the fix, I'm facing this same issue now

The click triggered a new page

Just check new page on on playwright docs

Answer

Clicking on Animated Elements with Playwright

When dealing with animated or moving elements in your tests, Playwright's auto-waiting feature is your best friend. It waits for elements to be stable before interacting with them. An element is considered stable when its bounding box stays the same for at least two animation frames.

Here's how you can use Playwright's page.click() method to interact with these elements:

await page.click('button', { force: true });

In this example, we're clicking a button. The { force: true } option bypasses actionability checks and forces a click event, even if the button is moving or animated.

But be careful! Forcing actions without proper synchronization can lead to unexpected behavior. Sometimes, waiting for specific conditions (like visibility) is a better approach. Always test your code thoroughly and adapt it to your specific needs.

Remember, Playwright is a powerful tool for handling complex scenarios in your tests. For more insights on how to master it, check out this comprehensive guide.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].