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
What Do You Depend On? When the Chain of Trust Breaks
Most teams rely on more than just their application code to ship software. What happens when one of…
Innovating for Equality: How Can Technology Address Racial Disparities?
How can developers use their skills to advance racial justice and equality? Share examples of tech solutions that…
Explorando os Conceitos Básicos do Kotlin: Parte I
💟 Eai, como cês tão? Essa é a primeira parte de um conteúdo que será dividido em duas…