赛普拉斯:我想从一个基于文本的元素列表中找到一个元素,并想点击
cy.get('partie-room-list-item > div > div.content-block > span.partie-title').each(($elm , i) => {
cy.get($elm).invoke('text').then((text) => {
if (text === 'textinelement') {
expect(text.trim()).equal('textinelement').click();
cy.log(text)
}
})
});
cypress find element and click https://www.screencast.com/t/p0rL6qexD5
答案 0 :(得分:1)
it("This test is for selecting a single element based on text",()=>{
cy.visit('http://automationpractice.com/index.php')
cy.get("[title='Women']").each(($element, index)=>{
console.log("Object is "+ $element.text())
if($element.text()=='Women'){
cy.get($element).click()
}
})
})
或
it("This test is for selecting a single element based on text",()=>{
cy.visit('http://automationpractice.com/index.php')
cy.get("[title='Women']").contains('Women').click()
})
答案 1 :(得分:0)
您能否尝试下面的代码,并让我知道结果。您可以使用.text()
从span元素获取文本。
cy.get('partie-room-list-item > div > div > .partie-title').each(ele => {
const eleText = "cypresssendfollowRequest";
if (ele.text() === eleText) {
ele.click();
}
});
答案 2 :(得分:0)
我只是在这里猜测。如果您发布HTML,我也许可以为您提供帮助
cy.get('.partie-title').contains('textinelement').click()
看着你的图像就像这样
cy.get('.partie-title').contains('cypresssendfollowRequest').click()