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
Creating a Minesweeper Game in SolidJS – Score, Timer and Game State
Welcome to the 3rd installment of the “Creating a Minesweeper Game in SolidJS” post series. In the first…
How to Deploy a Next.js 13 App to AWS with Amplify Hosting
Introduction AWS Amplify Hosting – the ultimate solution for fast, secure, and scalable web app deployment. Whether you’re…
How to Connect WSL2 (with Laravel App) to a XAMPP MySql Server on Windows
You have a MySql server running on Windows perhaps with XAMPP. You also have Wsl2 and want to…