This content originally appeared on DEV Community and was authored by Dennis Zhang
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"。
This content originally appeared on DEV Community and was authored by Dennis Zhang
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Dennis Zhang | Sciencx (2024-09-06T03:07:07+00:00) cypress查找元素. Retrieved from https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/
" » cypress查找元素." Dennis Zhang | Sciencx - Friday September 6, 2024, https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/
HARVARDDennis Zhang | Sciencx Friday September 6, 2024 » cypress查找元素., viewed ,<https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/>
VANCOUVERDennis Zhang | Sciencx - » cypress查找元素. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/
CHICAGO" » cypress查找元素." Dennis Zhang | Sciencx - Accessed . https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/
IEEE" » cypress查找元素." Dennis Zhang | Sciencx [Online]. Available: https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/. [Accessed: ]
rf:citation » cypress查找元素 | Dennis Zhang | Sciencx | https://www.scien.cx/2024/09/06/cypress%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.