我使用的是spectron 3.8.0,正在尝试检查am元素是否存在于DOM中。我尝试在try/catch中使用waitUntil方法,但它没有像预期的那样工作。最近我得到了同步app.client.isExisting()返回真,如果一个元素存在,但否则它会被卡住并抛出一个超时异常(mocha)。
代码如下:
@log
protected async isExisting(element: string, name?: string): Promise<boolean> {
await this.app.client.isExisting(element)
.then(data => {
const isExisting = data;
console.log(CONSOLE_COLORS.YELLOW, "IS EXISTING???", isExisting);
return isExisting;
})
.catch(e => {
console.log(CONSOLE_COLORS.RED, "no existing elem")
return false;
});
}发布于 2018-07-03 22:18:05
isExisting应该可以很好地工作。
你应该正确地返回promise
return app.client.isExisting('#element');这就像火花一样工作
如果给定的selector.if至少存在一个元素,则返回true,not将返回false
要等待一个元素,请使用下面的代码
doesexist(app, element) {
return app.client.waitforExist(element,60 * 1000);
}只需以更干净的方式传递需要checked.Much的应用程序和元素即可避免等待
如果元素在60秒之前存在,则返回true;如果不存在,则返回true;如果元素在60秒后不存在,则返回true
https://stackoverflow.com/questions/50183805
复制相似问题