我正在為一個包含一系列引文的網站撰寫賽普拉斯測驗,其中一些引文的末尾有一個“閱讀更多”按鈕,它顯示了引文的其余部分。如果我使用
cy.get(".quote")
它回傳幾個引號的串列。我可以用
cy.get(".quote").find(".read-more").first()
查找具有“閱讀更多”按鈕的第一個引號,但我想知道該元素的索引在原始引號串列中是什么。我正在測驗以確保“閱讀更多”按鈕正確顯示完整的參考,但是一旦單擊該按鈕就會消失(完全從 DOM 中洗掉,而不僅僅是設定為可見性:無),所以我不能使用相同的命令以再次查找報價。如果我可以訪問該參考的元素,我可以使用
cy.get(".quote").eq(element)
在“閱讀更多”按鈕消失后再次提取該特定報價。
uj5u.com熱心網友回復:
你可以做這樣的事情。應用each引號,然后在每次搜索中查找您要查找的報價,然后獲取該報價的索引。
cy.get('.quote').each(($ele, index) => {
if ($ele.text().includes('some part of the quote')) {
cy.log(index) //logs the index
}
})
uj5u.com熱心網友回復:
閱讀更多按鈕正確顯示完整報價,然后單擊后按鈕消失
假設按鈕在單擊后從參考元素read more中洗掉,那么您可以執行以下操作。.read-more
cy.get('.quote') // returns all quotes
.find('.read-more') // only quotes with 'read more'
.each(($quote) => {
cy.wrap($quote).find('.read-more-button').should('be.visible').click() //check read more button is visible, then click
cy.wrap($quote).invoke('text').should('include.text',COMPLETE_QUOTE) // you can alter the should to however you best see to the text assertion
cy.wrap($quote).find('.read-more-button').should('not.exist') // particular read more button does not exist in DOM
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/413751.html
標籤:
