Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testcafe Selector.exists doesn't return a boolean

I want to do some action in case Selector('#particularButton-view').exists is true and some other action in case is false.

The problem is that it doesn't return a boolean. It returns some object. It's made to be used like this:

testController.expect(Selector('#particularButton-view').exists).ok()

How can I do to perform some action in each case?

like image 311
user2849167 Avatar asked Mar 25 '26 17:03

user2849167


1 Answers

Selector properties are wrapped in Promises, so to obtain a value you can use await from ES2017:

await Selector('...').exists;

If you can't use await, you can get the value by using then method of the promise, like:

Selector('...')
    .exists
    .then(exists => {
        If (exists)
            Foo();
        else
            Bar();
    })
like image 78
Andrey Belym Avatar answered Mar 28 '26 07:03

Andrey Belym



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!