cy.get('div.infoTextCarousel').find('a.ProductInfoAnchor').should('have.attr', 'href', url)
有很多同名div为“ div.infoTextCarousel”的div,每个div中都有一个“ a.ProductInfoAnchor”,其中一个包含匹配的href。因此,我想要的是柏树一直在寻找匹配的href,直到找到匹配的href,但是问题是,当它找不到匹配的href时,它仅检查“ div.infoTextCarousel”和“ a.ProductInfoAnchor”中的第一个它失败。
您可以将回调函数传递给should(),以防需要更复杂的行为。在下面的代码中,我提取了href属性,并期望属性列表包含特定的url:
const url = '/something'
cy.get('div.infoTextCarousel')
.find('a')
.should($a => {
let hrefs = $a.map((i, el) => {
return Cypress.$(el).attr('href')})
expect(hrefs.get()).to.contain(url)
})
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句