The “contains” selector in Cypress is used to select elements that contain a specific text. By default, this selector performs a partial match, meaning it selects elements that contain the given text anywhere within their content. However, if you want to perform an exact match using the “contains” selector, you can achieve this by using the ‘exact’ option.
To use the ‘exact’ option in Cypress, you can pass it as an argument to the “contains” selector. Here’s an example:
cy.contains('button', 'Click Me', { matchCase: false, exact: true });
In this example, the “contains” selector is used to select a button element that has the exact text “Click Me”. The ‘exact’ option is set to “true”, ensuring that only elements with an exact match are selected. The ‘matchCase’ option is set to “false” to ignore the case sensitivity (e.g., “click me” or “Click Me” will both be selected).
Keep in mind that the “contains” selector with the ‘exact’ option can be used with any HTML element and any text content within that element. Adjust the element tag and the text accordingly in your actual code.
Read more interesting post
- Python setup.py bdist_wheel did not run successfully.
- ‘value’ is unavailable: introduced in ios 12.0
- Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
- Generic type ‘ɵɵdirectivedeclaration’ requires 6 type argument(s).
- Create artifact container failed: artifact storage quota has been hit. unable to upload any new artifacts