【发布时间】:2019-11-13 08:59:03
【问题描述】:
一旦收到后端响应,下拉菜单基本上需要很长时间才能自行加载。如果我等待大约 8 秒,那么它可以工作。但是,不想在这里对等待进行硬编码。知道可能出了什么问题吗?我也无法识别 css。
cy.get('input').last().type(`{selectall}${value}`);
cy.get('mat-option > span').then(option => {
if (option.get(0).textContent === 'Loading...') {
cy.wait(5000);
}
});
cy.containsCaseInsensitive(value, 'mat-option').first().scrollIntoView().debug().click();
错误日志 -
CypressError: Timed out retrying: cy.click() failed because this element is detached from the DOM.
<mat-option _ngcontent-gcj-c21="" class="mat-option ng-star-inserted" role="option" ng-reflect-value="[object Object]" tabindex="0" id="mat-option-104" aria-disabled="false" style="">...</mat-option>
Cypress requires elements be attached in the DOM to interact with them.
The previous command that ran was:
> cy.debug()
This DOM element likely became detached somewhere between the previous and current command.
Common situations why this happens:
- Your JS framework re-rendered asynchronously
- Your app code reacted to an event firing and removed the element
You typically need to re-query for the element or add 'guards' which delay Cypress from running new commands.
https://on.cypress.io/element-has-detached-from-dom
【问题讨论】: