question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`contains()` targets element with `pointer-events: none` and fails to click instead of targeting element higher up the tree

See original GitHub issue

Is this a Feature or Bug?

~Bug.~ A feature, I guess. Thought it was a bug, but it turns out contains does something else than what I originally assumed.

Current behavior:

I use UI components from Ant Design (React) and the button has the following mark-up:

<button type="button" class="ant-btn">
  <span>Some Label</span>
</button>

and the following style applied:

.ant-btn > span {
  pointer-events: none;
}

When I try to interact with the button using:

cy.get('button').contains('Some Label').click()

I get the following error message:

CypressError: Timed out retrying: cy.click() failed because this element:

<span>Create</span>

is being covered by another element:

<button type="button" class="ant-btn">…</button>

Fix this problem, or use {force: true} to disable error checking.

https://on.cypress.io/element-cannot-be-interacted-with

When I programmatically set pointer-events to auto, the issue disappears. Apparently the contains operator finds the <span> containing the text and then fails, because it has pointer-events: none.

Desired behavior:

The contains() should ideally react to the expected interaction request by selecting elements without pointer-events: none when possible. In this case, it should select the button and the click should be triggered on it.

Steps to reproduce:

https://github.com/hon2a/cypress-test-tiny/tree/hon2a/pointer-events-bug

Versions

Cypress: 3.0.1 OS: macOS 10.13.5 browser: Chrome 66.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jennifer-shehanecommented, Jun 22, 2020

Closing as resolved. This now prints an error correctly indicating that the element has pointer-events: none.

Screen Shot 2020-06-22 at 12 23 28 PM

If you’re experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

2reactions
jennifer-shehanecommented, Jun 6, 2018

This is actually not how .contains() was designed to work. It was specifically designed to prefer elements like button over span as documented here.

Can you try specifying a selector in .contains() like in the code below? This should definitely prefer the button. Let me know what the result is of this.

cy.contains('button', 'Some Label').click()
Read more comments on GitHub >

github_iconTop Results From Across the Web

pointer-events - CSS: Cascading Style Sheets - MDN Web Docs
The pointer-events CSS property sets under what circumstances (if any) a particular graphic element can become the target of pointer events.
Read more >
Pointer-events: none not working on child element
If I understand correctly, you want to click the .parent by going through the .child that doesn't register mouse clicks?
Read more >
Pointer Events - W3C
If the event is pointerdown , the associated device is a direct manipulation device, and the target is an Element , then set...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Added "Scroll" labels in the element tree for scrollable elements ... in the DOM tree is added or removed (254062@main); Prevented showing the...
Read more >
Pointer events - Unity - Manual
Pointer events always precede mouse events in UI Toolkit. Pointer events don't have a ... target : The visual element that receives the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found