我正在try 做一些与这篇帖子非常类似的事情: https://stackoverflow.com/questions/56145926/how-to-check-if-element-exists-using-cypress-io个
我正在使用类型转换.以下是我的代码:
cy.get("body").then($body => {
if ($body.find(this.timerLocator).length > 0) {
return cy.get(this.timerLocator);
}
else {
return cy.contains('No Match Found');
}
});
问题是,"this.timerLocator"可能要等上60秒才会出现. find个命令的文档提到我们可以传递一个选项‘Timeout’. 但在添加超时时,我收到以下错误消息:
cy.get("body").then($body => {
if ($body.find(this.timerLocator, {timeout: 60000}).length > 0) {
return cy.get(this.timerLocator);
}
else {
return cy.contains('No Match Found');
}
});
Expected 1 arguments, but got 2.ts(2554)
我还try 了一些简单得多的方法,比如:
try {
cy.get(this.timerLocator, { timeout: 60000 });
} catch (error) {
cy.contains('No Match Found');
}
但这并不管用.我从来没有拿到过接球支架.
有人能在这件事上帮我一下吗?
EDIT:实际上,我最终使用了多个 Select 器,它在我的情况下工作得很好.以下是我的代码:
const multiSelector = `${this.timerLocator}, :contains("No Match Found")`;
return cy.get(multiSelector, { timeout: 60000 });