cy.get('.item') // 这会返回所有 class 为 'item' 的元素
cy.get('.item').eq(1) // 获取第二个 'item' 元素
cy.get('.item').eq(1).should('contain', 'Item 2') // 检查第二个 .item 元素是否包含文本 "Item 2"。
// .invoke('text') 方法来获取元素内的文本
cy.get('.item').eq(1).invoke('text').then((text) => {
// 此时 text 包含了第二个 .item 元素的文本,即 'Item 2'
cy.log(text); // 在 Cypress 的日志中显示获取的文本
});
cy.get('.item').eq(1).invoke('text').should('eq', 'Item 2');
// 这会检查第二个 item 元素的文本是否正好等于 "Item 2"。
Related Posts
Part 1.1 – Build a fullstack blogging website using MERN ( MongoDB, ReactJS, ExpressJS and NodeJS )
👋 Hey there, today in this blog we will start a new series where we will learn “how to…
New Year New Me: 17 Best Programming Books for Beginner Devs 2025
Let’s be honest – starting your programming journey can be overwhelming. With countless resources available online, finding the…
Thank you so much everyone!
Hi fam, I’m so excited to announce that I’ve reached 30,000 views and 6K+ followers! This is such…