Cypress测试中如何验证select下拉框不存在指定的option选项值
Cypress验证select下拉不存在指定option的实现方法
你可以根据校验目标是option的展示文本还是value属性选择对应写法:
- 校验展示文本(精确匹配,避免部分匹配误判)
cy.get('select') .find('option') .filter((_, el) => el.textContent.trim() === 'C') .should('have.length', 0)
如果不需要严格精确匹配,可以用更简洁的写法:
cy.get('select').find('option:contains("C")').should('not.exist')
- 校验option的value属性
// 示例校验value值为"C"的option不存在 cy.get('select').find('option[value="C"]').should('not.exist')
内容的提问来源于stack exchange,提问作者kodeaben
相关产品推荐
相关产品推荐

