[BUG] Page.click() doesn't work when target is covered by animating element
See original GitHub issueContext:
- Playwright Version: 0.13.0
- Operating System: macOS
Describe the bug
Hi team. I’m having an issue with page.click()
failing. This is happening in the context of React and Vue apps. I haven’t been able to create a reliable reproduction, but I have a couple of clues.
- In cases where the click fails, the visual state of the element changes and it appears to be in a hover state
- If I use
page.$eval(selector, (element) => element.click())
in these cases, the click does work
Could you shed some light on what the differences are between page.click(selector)
and page.$eval(selector, (element) => element.click())
? This may help me create a reproduction case for this issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
puppeteer element.click() not working and not throwing an error
It wouldn't work for an element that was continually moving or for an element that is covered by something else. For those cases,...
Read more >Error - Click not executed | Checkly
Possible causes. Not-so-obvious: the element we are trying to click is on the page, but is not the one receiving the click; there...
Read more >Element: click event - Web APIs | MDN
An element receives a click event when a pointing device button (such as a mouse's ... The secondary target for the event, if...
Read more >Common Issues | Swup
People tend to use a class with a format of transition-[something] on any element that is animating, which is not necessary and often...
Read more >Using CSS Transition Opacity for Fade Effects, Problems and ...
On the other hand links covered by an fully transparent element do not work, although completely visible. The following first example illustrates this....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dgozman @pavelfeldman I was able to create a repro for one of my cases! It turns out that the element I was trying to click was covered by an invisible element. That element begins to animate out of the way upon hover, but at the time of the click it’s still covering the center of the button I want to click.
So IMO the bug is that Playwright should tell me that this element isn’t interactable, but instead it tells me it successfully clicked the button.
Here’s the codepen link in case the debug URL expires. https://codepen.io/celeryclub/pen/yLYJLXM?editors=0110
@celeryclub thanks for the report!
page.$eval(selector, (element) => element.click())
performs a soft programmatic click on the element that corresponds to the selector.page.click(selector)
is a real click for testing. It’ll locate the element, wait for it to become visible, wait for it to receive input events when clicked in the center of its box, wait for it to stop moving. It’ll then perform mouse operations as if the user was clicking the mouse or tapping a phone screen. Browser would think those are real events, they also will be trusted.Run your app with
DEBUG=pw:input
to see where it stalls. It is likely that the last line of the log will bewaiting for element to receive pointer events at (x, y)
.