【发布时间】:2021-03-11 12:43:50
【问题描述】:
如何使用赛普拉斯点击收藏按钮?我试过了:
cy.contains('img', {matchCase: false}).click({force: true});
cy.get('[alt="Image"]').click();
cy.get('[src="Images/outline_star_border_black_18dp.png"]').click({force: true});
【问题讨论】:
如何使用赛普拉斯点击收藏按钮?我试过了:
cy.contains('img', {matchCase: false}).click({force: true});
cy.get('[alt="Image"]').click();
cy.get('[src="Images/outline_star_border_black_18dp.png"]').click({force: true});
【问题讨论】:
我会通过获取工具栏并深入了解它,
cy.get('.topbar') // get the containing toolbar
.children() // all the children with it
.eq(1) // take the second one
.find('img') // all the icons
.eq(0) // take the first one (NOTE they are reverse order to display)
.click()
或者使用.find()和部分匹配的源字符串在工具栏中搜索
cy.get('.topbar') // get the containing toolbar
.find('img[src*="outline_star"]') // *= gives a partial match on src
.click()
【讨论】:
嗯,这样的事情会有所帮助。首先通过 cy.xpath() 或 cy.get() 找到元素,然后过滤更像具有 src 标签的元素,然后如果 >src 具有包含 outline_star_border_black 的 url,然后单击元素简单:)
const elem= cy.xpath('div[class="main"]>div:nth-child(2)>div>
img:nth-child(1)').should('have.attr', 'src')
if (elem.should('contain', 'outline_star_border_black')) {
elem.click()
}
【讨论】: