.type()

To type into a DOM element, use the .type() command.

cy.get('.action-email')
  .type('[email protected]').should('have.value', '[email protected]')

  // .type() may include special character sequences
  .type('{leftarrow}{rightarrow}{uparrow}{downarrow}{del}{selectall}{backspace}')

  // .type() may additionally include key modifiers
  .type('{alt}{option}')        //these are equivalent
  .type('{ctrl}{control}')      //these are equivalent
  .type('{meta}{command}{cmd}') //these are equivalent
  .type('{shift}')

  // **** Type Options ****
  // .type() accepts options that control typing

  // Delay each keypress by 0.1 sec
  .type('[email protected]', {delay: 100})
  .should('have.value', '[email protected]')

cy.get('.action-disabled')
  // Ignore error checking prior to type
  // like whether the input is visible or disabled
  .type('disabled error checking', {force: true})
  .should('have.value', 'disabled error checking')

.focus()

To focus on a DOM element, use the .focus() command.

cy.get('.action-focus').focus()
  .should('have.class', 'focus')
  .prev().should('have.attr', 'style', 'color: orange;')

.blur()

To blur on a DOM element, use the .blur() command.

cy.get('.action-blur').type('I\'m about to blur').blur()
  .should('have.class', 'error')
  .prev().should('have.attr', 'style', 'color: red;')

.clear()

To clear on a DOM element, use the .clear() command.

cy.get('.action-clear').type('We are going to clear this text')
  .should('have.value', 'We are going to clear this text')
  .clear()
  .should('have.value', '')

.submit()

To submit a form, use the cy.submit() command.

cy.get('.action-form')
  .find('[type="text"]').type('HALFOFF')
cy.get('.action-form').submit()
  .next().should('contain', 'Your form has been submitted!')

.click()

To click a DOM element, use the .click() command.

cy.get('.action-btn').click()

// clicking in the center of the element is the default
cy.get('#action-canvas').click()

cy.get('#action-canvas').click('topLeft')
cy.get('#action-canvas').click('top')
cy.get('#action-canvas').click('topRight')
cy.get('#action-canvas').click('left')
cy.get('#action-canvas').click('right')
cy.get('#action-canvas').click('bottomLeft')
cy.get('#action-canvas').click('bottom')
cy.get('#action-canvas').click('bottomRight')

// **** Click Coordinate ****

// .click() accepts a an x and y coordinate
// that controls where the click occurs :)
cy.get('#action-canvas')
  // click 80px on x coord and 75px on y coord
  .click(80, 75)
  .click(170, 75)
  .click(80, 165)
  .click(100, 185)
  .click(125, 190)
  .click(150, 185)
  .click(170, 165)

// **** Click Options ****

// .click() accepts options that control clicking

// click multiple elements by passing multiple: true
// otherwise an error will be thrown if multiple
// elements are the subject of cy.click
cy.get('.action-labels>.label').click({multiple: true})

// Ignore error checking prior to clicking
// like whether the element is visible, clickable or disabled
// this button below is covered by another element.
cy.get('.action-opacity>.btn').click({force: true})

Canvas to Illustrate Click Positions

click me and me and me and me and me and me


.dblclick()

To double click a DOM element, use the .dblclick() command.

cy.get('.action-div').dblclick().should('not.be.visible')
cy.get('.action-input-hidden').should('be.visible')
Double click to edit

.check()

To check a checkbox or radio, use the .check() command.

cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').check().should('be.checked')

cy.get('.action-radios [type="radio"]').not('[disabled]').check().should('be.checked')

// .check() accepts a value argument
// that checks only checkboxes or radios
// with matching values
cy.get('.action-radios [type="radio"]').check('radio1').should('be.checked')

// .check() accepts an array of values
// that checks only checkboxes or radios
// with matching values
cy.get('.action-multiple-checkboxes [type="checkbox"]').check(['checkbox1', 'checkbox2']).should('be.checked')

// .check() accepts options that control checking

// Ignore error checking prior to checking
// like whether the element is visible, clickable or disabled
// this checkbox below is disabled.
cy.get('.action-checkboxes [disabled]')
  .check({force: true}).should('be.checked')

cy.get('.action-radios [type="radio"]').check('radio3', {force: true}).should('be.checked')



.uncheck()

To uncheck a checkbox or radio, use the .uncheck() command.

cy.get('.action-check [type="checkbox"]')
  .not('[disabled]')
  .uncheck().should('not.be.checked')

// **** Uncheck Value ****

// .uncheck() accepts a value argument
// that unchecks only checkboxes
// with matching values
cy.get('.action-check [type="checkbox"]')
  .check('checkbox1')
  .uncheck('checkbox1').should('not.be.checked')

// **** Uncheck Values ****

// .uncheck() accepts an array of values
// that unchecks only checkboxes or radios
// with matching values
cy.get('.action-check [type="checkbox"]')
  .check(['checkbox1', 'checkbox3'])
  .uncheck(['checkbox1', 'checkbox3']).should('not.be.checked')

// **** Uncheck Options ****

// .uncheck() accepts options that control unchecking

// Ignore error checking prior to unchecking
// like whether the element is visible, clickable or disabled
// this checkbox below is disabled.
cy.get('.action-check [disabled]')
  .uncheck({force: true}).should('not.be.checked')

.select()

To select an option in a select, use the .select() command.

// Select option with matching text content
cy.get('.action-select').select('apples')

// Select option with matching value
cy.get('.action-select').select('fr-bananas')

// Select options with matching text content
cy.get('.action-select-multiple').select(['apples', 'oranges', 'bananas'])

// Select options with matching values
cy.get('.action-select-multiple').select(['fr-apples', 'fr-oranges', 'fr-bananas'])

.scrollIntoView()

To scroll an element into view, use the .scrollintoview() command.

// normally all of these buttons are hidden, because they're not within
// the viewable area of their parent (we need to scroll to see them)
cy.get('#scroll-horizontal button')
  .should('not.be.visible')

// scroll the button into view, as if the user had scrolled
cy.get('#scroll-horizontal button').scrollIntoView()
  .should('be.visible')

cy.get('#scroll-vertical button')
  .should('not.be.visible')

// Cypress handles the scroll direction needed
cy.get('#scroll-vertical button').scrollIntoView()
  .should('be.visible')

cy.get('#scroll-both button')
  .should('not.be.visible')

// Cypress knows to scroll to the right and down
cy.get('#scroll-both button').scrollIntoView()
  .should('be.visible')
Horizontal Scroll
Vertical Scroll
Both Scroll

cy.scrollTo()

To scroll the window or a scrollable element to a specific position, use the cy.scrollTo() command.

// if you chain scrollTo off of cy, we will
// scroll the entire window
cy.scrollTo('bottom')

cy.get('#scrollable-horizontal').scrollTo('right')

// or you can scroll to a specific coordinate:
// (x axis, y axis) in pixels
cy.get('#scrollable-vertical').scrollTo(250, 250)

// or you can scroll to a specific percentage
// of the (width, height) of the element
cy.get('#scrollable-both').scrollTo('75%', '25%')

// **** Scroll Options ****

// cy.scrollTo() accepts options that control scrolling behavior

// control the easing of the scroll (default is 'swing')
cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear'} )

// control the duration of the scroll (in ms)
cy.get('#scrollable-both').scrollTo('center', { duration: 2000} )
Horizontal Scroll
Vertical Scroll
Both Scroll

.trigger()

To trigger an event on a DOM element, use the .trigger() command.

cy.get('.trigger-input-range')
  .invoke('val', 25)
  .trigger('change')
  .get('input[type=range]').siblings('p')
  .should('have.text', '25')

0