Search code examples
javascriptwebdriverwebdriver-io

Webdriver.io: isExisting().then() is not a function


I would like to check if there is a logout element. If it is existing, I want to do the logout by clicking this element:

browser.isExisting('.logout').then(function() {
    browser.click('.logout');
});

But this gives me an Uncaught TypeError: browser.isExisting(...).then is not a function-error.


Solution

  • If your using a version <4, you want this. http://webdriver.io/v3.4/api/utility/waitForExist.html

    browser.waitForExist('.logout').then(function() {
        browser.click('.logout');
    });
    

    But if you use V4+, everything is synchronous ( http://webdriver.io/guide/getstarted/v4.html ), and you would need to rewrite a bit. http://webdriver.io/api/utility/waitForExist.html

    Something like this

    var logout = browser.element('.logout');
    logout.waitForExist(5000);
    browser.click('.logout');