我试图通过表格上的链接列表,并确保下一页有正确的URL,但遇到了问题.一个问题是没有好的类名可用,所以我一直使用cy.xPath.
//Loop through each element (This is a dynamic amount of elements)
cy.xpath('//span[text()="Id"]//following::a[contains(@href,"maps")]'.each($el) => {
cy.get($el).then(($btn) => {
let id_text = $btn.text()
//Check that the element is visible and click on it
cy.get($el)
.should('be.visible')
.click()
//Check that the url contains the text value of the element that was clicked on
cy.url()
.should('contain', id_text)
})
})
它只工作了一次,然后就出错了,说DOM元素分离了