-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Cypress - get element with 2 attributes
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Get element with two attributes | ||
|
||
It's possible to use two attributes to target an element with the `get()` command. | ||
|
||
This is useful when targeting an element that's generated by a framework or library and can't receive a custom `id` or `data-` attribute. | ||
|
||
Given this element: | ||
|
||
```html | ||
<div data-component="tab" data-value="first_tab"></div> | ||
``` | ||
|
||
You can select it like this: | ||
|
||
```js | ||
cy.get('[data-component="tab"][data-value="first_tab"]').click(); | ||
``` | ||
|
||
Cypress follows the jQuery multiple attribute selector | ||
|
||
## References | ||
|
||
- StackOverflow [answer](https://stackoverflow.com/questions/61763473/how-to-add-two-data-attribute-check-in-cypress) | ||
- jQuery [Docs](https://api.jquery.com/multiple-attribute-selector/) |