您已经完成了一半,移除部分有效。要添加selected
到Cancelled
,调用attr
// remove
cy.get('select')
.find(':selected')
.should('contain', 'Active')
.invoke('removeAttr', 'selected')
// add
cy.get('select')
.find('option')
.contains('Cancelled')
.invoke('attr', 'selected', true)
//confirm
cy.get('select')
.find(':selected')
.should('contain', 'Cancelled')
这给你
<option selected="selected">Cancelled</option>
如果你更喜欢
<option selected>Cancelled</option>
改用这个
// add
cy.get('select')
.find('option')
.contains('Cancelled')
.then($el => $el[0].setAttribute('selected', ''))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句