cypress-io / cypress-example-kitchensink

This is an example app used to showcase Cypress.io testing.

Home Page:https://example.cypress.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

it there any api to find the first element that following an specific element

justforuse opened this issue · comments

commented

Take cypress.io as an example, I want to get the first div that following the h1 element.

image

and I wrote this file:

describe('Cypress', () => {
  it('next with selecor', () => {
    cy.visit('https://www.cypress.io/')
    cy.get('h1').next('div').find('button')
  })
})

seems next not work as I expected. it give me an error:
image

If I add another .next(), it works as expected:
cy.get('h1').next().next('div').find('button')

I just wonder is there an api can deal with this situation? because we may not know the number of elements between div and h1.

thanks.