1

I am using spectron 3.8.0 and am trying to check if am element exists in the DOM. I tried using the waitUntil method with try/catch, but it didn't work as expected. Recently I got sync app.client.isExisting() return true if an element exists, but otherwise it gets stuck and throws a timeout exception (mocha).

Code below:

@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;
        });
}
pushkin
  • 9,575
  • 15
  • 51
  • 95
zaebalo
  • 147
  • 2
  • 12
  • 2
    I'm not certain how `isExisting()` is supposed to be called, but it seem like you should be returning the promise from `this.app.client.isExisting()`. You're awaiting it, but not getting or returning the final value. – Mark May 04 '18 at 22:26

1 Answers1

0

isExisting should work fine.

You should return promise correctly

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

This worked like spark

Returns true if at least one element is existing by given selector.if not will return false

For waiting for an element please use the below

doesexist(app, element) {
    return app.client.waitforExist(element,60 * 1000);
}

Just pass the app and element that need to be checked.Much cleaner way to avoid await

Returns true if element exist before 60 seconds if not error telling doesnot exist after 60 seconds

Bharath Kumar S
  • 1,410
  • 2
  • 10
  • 29