Skip to content

Commit

Permalink
add Cypress - get element with 2 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
drecali committed Aug 5, 2022
1 parent 9ecaa2b commit 3037aa1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ This repo is inspired by the [@jbrandchaud/til](https://github.com/jbranchaud/ti
### Cypress

- [Check if loading is finished](cypress/check-if-loading-finished.md)
- [Get element with two attributes](cypress/get-element-with-two-attributes.md)
- [Headless login custom command](cypress/headless-login-custom-command.md)
- [Override global configs for one test/suite](cypress/override-global-configs-one-test-suite.md)
- [`[Plugin]` - `cypress-terminal-report` for instant headless debug info](cypress/plugin-cypress-terminal-report-instant-headless-debug-info.md)
Expand Down
24 changes: 24 additions & 0 deletions cypress/get-element-with-two-attributes.md
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/)

0 comments on commit 3037aa1

Please sign in to comment.