1. children(),parent(),parents()
children()寻找子元素
parent()寻找父元素
parents()寻找所有父dom元素,结果是多个dom元素
parentsUntil(selector)寻找所有父元素直到匹配的元素,结果是多个dom元素。

cy.get('.traversal-breadcrumb')
.children('.active')
.should('contain', 'Data')
cy.get('.active')
.parent()
..should('have.class', 'traversal-breadcrumb')
2. closest()
寻找最近的父元素

cy.get('.traversal-badge')
.closest('ul')
.should('have.class', 'list-group')
3. 多种方法定位列表中的元素
eq(),first(),last(),next(),nextAll(),nextUntil(),prev()
eq()获取特定索引的dom元素(索引从0开始)
first()获取第一个元素
last()获取最后一个元素
next()获取下一个元素
nextAll()获取剩下的所有元素
nextUntil(selector)获取后面所有元素直到匹配到selector为止,结果是多个dom元素
prev()获取上一个元素
prevAll()获取前面的所有元素
prevUntil(selector)获取前面所有元素直到匹配到selector为止,结果是多个dom元素
siblings()获取所有同级元素,不包括自己

cy.get('.traversal-list>li')
.eq(1).should('contain', 'siamese')
cy.get('.traversal-list>li')
.first().should('contain', 'tabby')
cy.get('traversal-list>li')
.last().should('contain', 'burmese')
cy.get('.traversal-list>li')
.first().next().should('contain', 'siamese')
cy.get('.traversal-list>li')
.first().nextAll().should('have.length', '4')
cy.get('.traversal-list>li')
.first().nextUntil('.traversal-list>li:last').should('have.length', '3')
4. filter(),not()
filter()获取与特定selector匹配的元素
not()获取与特定selector不匹配的元素

cy.get('.traversal-nav>li')
.filter('.active').should('contain', 'About')
cy.get('.traversal-nav>li')
.not('.active').should('not.contain', 'About')
5. find()
获取后代中的元素

cy.get('.traversal-pagination').find('li').find('a').should('have.length', 7)
本文是Cypress基础教程的第三部分,详细介绍了Cypress中用于元素遍历的各种方法,如children(), parent(), parents()等,以及如何通过closest(), eq(), first(), last(), next(), prev()等进行元素定位。同时,还涵盖了filter(), not()和find()等筛选元素的实用技巧。"
113673128,10539617,Python绘制心形:matplotlib与sympy实现,"['Python画图', 'matplotlib', 'sympy']
881

被折叠的 条评论
为什么被折叠?



