-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cy.click algorithm may incorrectly calculate elements with display: inline #210
Comments
the plural document.elementsFromPoint does exist, in case the stack of elements underneath would be more useful to you. |
That won't help because essentially that's the same thing as Cypress's algorithm basically works like this: when attempting to interact with an element, first determine if its being "covered" by another element. After we determine the center of the element (or another position if you've passed that as an option), we then determine using If a non-descendent element is returned then we assume it to be covered. We talked as a team and likely the best solution for this is starting from the center and then expanding out in a square based on some interpolated step value until both the However that's way too much work for the time being, so we're just going to flip the elements CSS to Once it's |
Released in |
I'm having a similar problem: let stuff = [];
cy.get('mat-select').each((select) => {
stuff.push(select);
}).then(()=>{
stuff[1].click();
cy.get('mat-option').first().click();
}); this works with stuff[0].click();
cy.get('mat-option').first().click();
stuff[1].click();
cy.get('mat-option').first().click(); it will fail because it opens both selects at the same time. So it will say |
@robert-king I'm not sure I understand. Can you provide some screenshots or a reproducible? |
Hey @robert-king, this original issue was involving inline elements issuing the error Could you open a new issue outlining an example that we can reproduce locally including the application code and test code. You can also try asking questions relating to how to use Cypress be asked in our community chat. |
In this screenshot Cypress is failing with the following error:
The reason this is happening is because the
<a>
subject attempting to be clicked has CSSdisplay: inline
.Display inline causes elements not to displace contents between the text.
When Cypress calculates the elements position to ensure it is not being covered by another element it uses
document.elementFromPoint(x, y)
to return the lowest descendent in the DOM.If an
inline
element's exact center is calculated to be between the text, then this will return the element underneath the target (which is correct).Unfortunately since Cypress was returned a non-descendent it believes the element is currently being covered and therefore displays the error.
To fix this, Cypress will need to take this situation into account by applying some fallback logic for this specific condition. I'm not sure what it should do yet, perhaps change the CSS to
display: inline-block
, calculate the center coordinates again, and if the element is found, revert to the original CSS and then click the element.The text was updated successfully, but these errors were encountered: