javascript - Webdriver.io: isExisting().then() is not a function - Stack Overflow

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

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.

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.

Share Improve this question asked Jul 21, 2016 at 8:29 user3142695user3142695 17.4k55 gold badges200 silver badges375 bronze badges 1
  • Is the purpose of your code is that you want to ensure that .logout exists before clicking on it? – garajo Commented Aug 5, 2016 at 8:23
Add a ment  | 

3 Answers 3

Reset to default 2

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');

Rewrite it to use object

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

https://webdriver.io/docs/api/element/isExisting.html You using 4.0 syntax for 5.0 webdriver.io

Check https://github./webdriverio/webdriverio/blob/master/CHANGELOG.md#v500-2018-12-20 for more

You can look here: http://webdriver.io/api/state/isExisting.html

client.isExisting(selector);

Returns boolean. So your code should look something like this:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745390137a4625623.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信