mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-22 16:18:45 -05:00
53 lines
1.0 KiB
Markdown
53 lines
1.0 KiB
Markdown
---
|
|
title: Cypress.$
|
|
comments: false
|
|
---
|
|
|
|
Cypress automatically includes {% url 'jQuery' http://jquery.com %} and exposes it as `Cypress.$`.
|
|
|
|
Calling `Cypress.$('button')` will automatically query for elements in your remote `window`. In other words, Cypress automatically sets the `document` to be whatever you've currently navigated to via {% url `cy.visit()` visit %}.
|
|
|
|
This is a great way to *synchronously* query for elements when debugging from Developer Tools.
|
|
|
|
# Syntax
|
|
|
|
```javascript
|
|
Cypress.$(selector)
|
|
|
|
// other proxied jQuery methods
|
|
Cypress.$.Event
|
|
Cypress.$.Deferred
|
|
Cypress.$.ajax
|
|
Cypress.$.get
|
|
Cypress.$.getJSON
|
|
Cypress.$.getScript
|
|
Cypress.$.post
|
|
```
|
|
|
|
## Usage
|
|
|
|
**{% fa fa-check-circle green %} Correct Usage**
|
|
|
|
```javascript
|
|
Cypress.$('p')
|
|
```
|
|
|
|
**{% fa fa-exclamation-triangle red %} Incorrect Usage**
|
|
|
|
```javascript
|
|
cy.$('p') // Errors, cannot be chained off 'cy'
|
|
```
|
|
|
|
# Examples
|
|
|
|
## Selector
|
|
|
|
```javascript
|
|
var $li = Cypress.$("ul li:first")
|
|
|
|
cy.wrap($li)
|
|
.should("not.have.class", "active")
|
|
.click()
|
|
.should("have.class", "active")
|
|
```
|