You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 02:39:02