如何使用赛普拉斯在页面中显示定位器的条件

How to write condition for locator is present in the page using Cypress

我正在 cypress 中寻找条件来验证点击定位器是否存在。 如果存在元素,则转到条件并单击该元素,否则离开并继续执行。下面的代码我试过了,

    cy.get(".paginationPanel.ng-star-inserted").then(($test)=> {
    if($test.text().includes('Show:')){
        //do something
    }else{

    }
})

很遗憾,我无法成功。谁能帮帮我吗。

该代码有效,有什么问题吗?

你想点击什么? “显示”下拉菜单为

cy.get(".paginationPanel").then(($panel) => {

  if($panel.text().includes('Show:')) {

    cy.contains('label', 'Show').prev().click()  // click the Show dropdown

  } else {
    
  }
})