无法使用Cypress单击元素

无法使用Cypress单击元素,cypress,Cypress,我点击输入栏,弹出项目列表。但我不能点击任何项目 cy.get('#field') .click({force:true}) //popup with items list appers cy.get('.ant-select-dropdown-menu') .should('be.visible') .contains('Item123', { timeout: 20000}) .click({force:true}) 错误: Timed out retrying:

我点击输入栏,弹出项目列表。但我不能点击任何项目

cy.get('#field')
  .click({force:true})   //popup with items list appers

cy.get('.ant-select-dropdown-menu')
  .should('be.visible')
  .contains('Item123', { timeout: 20000})
  .click({force:true})  
错误:

Timed out retrying: Expected to find content: 'Item123' within the element: <ul.ant-select-dropdown-menu> but never did.
重试超时:应在元素中找到内容:“Item123”:但从未找到。
我使用这个html。 我单击该字段,弹出窗口显示项目列表。我想点击任意项目。 html:


  • 项目1
  • 项目12
  • 项目123
  • 项目1234
您可以使用获取元素数组中特定索引处的DOM元素:

cy.get('li.ant-select-dropdown-menu-item', {
  timeout: 20000
}).eq(2).click({
  force: true
})

“ant…”是类名吗?如果是这样的话,它前面不是需要一个“.”吗?我忘了“.”,问题是存在的。你为什么投负号?我没有投反对票,其他人可能投了反对票,因为你没有发布你正在测试的实际代码,所以我们自己无法重现这个问题。看来
让我们更接近了!您确定菜单中有一个字符串
Item123
?你能分享一些代码吗?@JBallin我添加html代码
cy.get('li.ant-select-dropdown-menu-item', {
  timeout: 20000
}).eq(2).click({
  force: true
})