我相信这里发生的事情是对该waitForDeletedByXPath方法的作用的轻微误解。
该方法的文档说的是:
“等待此元素内与给定名称属性匹配的所有元素被销毁。”
当您的加载图标消失时,它很可能仍然是 DOM 的一部分,尽管它只是设置为不可见。此方法期望元素根本不再是 DOM 的一部分。
根据我的经验,您需要做的是为您的加载图标设置自己的“等待元素不可见”方法。
例如:
return this.remote
.then(function () {
const waitForLoadingIconNotDisplayed = function (remoteSession) {
return remoteSession
.findByCssSelector('your_loading_icon_css_selector')
.isDisplayed()
.then(function (isDisplayed) {
if (isDisplayed) {
return waitForLoadingIconNotDisplayed(remoteSession);
}
return true;
});
};
return Promise.all([waitForLoadingIconNotDisplayed(this.parent)]);
})
这将循环直到满足条件,即您的加载图标不再设置为使用Promise.all()调用在 UI 中显示。
希望这有助于引导您沿着正确的道路前进!