Skip to content
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

docs: add example to expand the usage of the get method #5469

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/queries/get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ cy.get('form').within(() => {
})
```

#### Find an anchor element by its label/text, remove some attribute and click it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to an add explanation of why this is useful. Something like:

Suggested change
The following may be useful to change remove a `target` of `"_blank"` before clicking a link that would otherwise launch a new tab/window:

```javascript
cy.get('a', { name: 'My link text' }).invoke('removeAttr', 'target').click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax here is not correct - it looks like a mix of Cypress and Testing Library syntax, the following would work though:

Suggested change
cy.get('a', { name: 'My link text' }).invoke('removeAttr', 'target').click();
cy.contains('a', 'hello').invoke('removeAttr', 'target').click();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marktnoonan

If the example is changed from cy.get() to cy.contains(), would it then need to be added to https://github.com/cypress-io/cypress-documentation/blob/main/docs/api/queries/contains.mdx instead?

```

### Get vs Find

The `cy.get` command always starts its search from the
Expand Down