javascript - Spectron异步isExisting不会返回false

标签 javascript webdriver electron webdriver-io spectron

我正在使用Spectron 3.8.0,并试图检查DOM中是否存在元素。我尝试将waitUntil方法与try/catch结合使用,但未按预期工作。最近,如果元素存在,我得到了同步app.client.isExisting()返回true,但是否则它会被卡住并抛出超时异常(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;
        });
}

最佳答案

isExisting应该可以正常工作。

您应该正确返回 promise

return app.client.isExisting('#element');

这像 Spark 一样工作

如果给定选择器至少存在一个元素,则返回true。否则返回false

等待元素,请使用以下内容
doesexist(app, element) {
    return app.client.waitforExist(element,60 * 1000);
}

只需通过需要检查的应用程序和元素即可。避免等待的更简洁方法

如果元素在60秒之前存在,则返回true;如果在60秒之后不存在错误提示,则返回true

关于javascript - Spectron异步isExisting不会返回false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50183805/

相关文章:

python - Selenium、python 和 linux 中的 Chrome webdriver 问题

python - 网站检测到 selenium webdriver

reactjs - 如何在 TypeScript 中使用 Electron <webview> 标签?

javascript - 将 Node 文件流图像传递给 HTML5 FileReader API

node.js - Electron Builder 中不存在应用程序入口文件

javascript - Kendo UI - 来自 JSON 数组的柱形图

javascript - 在我的目录中显示图像时,如何向其添加返回(或后退)按钮?

javascript - jQuery - 获取任何一组复选框的选中值

javascript - linq.js 意外结果

java - Selenium 不使用 InternetExplorerDriver 单击按钮的解决方法