Files
cypress/docs/source/api/commands/within.md
T
2017-05-23 17:17:27 -04:00

52 lines
1017 B
Markdown

---
title: within
comments: true
description: ''
---
Reset the root scope to the current subject and pass that as an argument to the callback function.
| | |
|--- | --- |
| **Returns** | the new DOM element(s) found by the command. |
| **Timeout** | *cannot timeout* |
# [cy.within( *function* )](#usage)
Set the root scope to the current subject
# Options
Pass in an options object to change the default behavior of `cy.within`.
**cy.within( *options*, *function* )**
Option | Default | Notes
--- | --- | ---
`log` | `false` | Display command in command log
# Usage
## Get inputs within a form and submit the form
```html
<form>
<input name="email" type="email">
<input name="password" type="password">
<button type="submit">Login</button>
</form>
```
```javascript
cy.get('form').within(function(){
cy
.get('input[name="email"]').type('john.doe@email.com')
.get('input[name="password"]').type('password')
.root().submit()
})
```
# See also
- [root](https://on.cypress.io/api/root)