getUsertextbox4() 
{
  cy.get('#multiselect-field-label-1')
}
 getsubmitButton() 
{
  cy.get('.security--button');
}这是我使用的代码,当第一个元素找不到时,测试就停止了,如何让测试继续下去,并验证测试套件中的其他东西?
发布于 2020-08-04 22:00:41
你可以这样做:
getUsertextbox4() 
{
  cy.get('body').then(($body) => {
      if ($body.find('#multiselect-field-label-1').length) {
          // continue the test
      } else {
          // you can throw error here, or just print out a warning message
          // and keep testing other parts of your code, eg:
          Cypress.log({ warning: 'unable to find the element' });
          getsubmitButton()
          ...
      }
  });
}这之所以有效,是因为<body>始终在那里,并且您可以通过检查主体上是否存在目标元素来自定义操作。
https://stackoverflow.com/questions/63068925
复制相似问题