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
Common Memory Leaks in JavaScript
1. Global Variables Global variables persist throughout the application’s lifetime and are rarely garbage collected. When variables are…
10 Best React Libraries for Building User Interfaces
React is a popular JavaScript library for building user interfaces. It provides developers with a simple and efficient…
2733. LeetCode’s Neither Minimum nor Maximum – JAVA SOLUTION BEATS 100% OF SOLUTIONS IN BOTH RUNTIME AND MEMORY
Code class Solution { public int findNonMinOrMax(int[] nums) { int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for…