Webdriver.io:isExisting().then()不是函数

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

本文关键字:函数 then io isExisting Webdriver      更新时间:2023-09-26

我想检查是否有logout元素。如果它已经存在,我想通过点击这个元素来注销:

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

但这给了我一个Uncaught TypeError: browser.isExisting(...).then is not a function-错误。

如果您使用的是<4,你想要这个。http://webdriver.io/v3.4/api/utility/waitForExist.html

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

但如果使用V4+,则所有内容都是同步的(http://webdriver.io/guide/getstarted/v4.html),并且您需要重写一点。http://webdriver.io/api/utility/waitForExist.html

像这样的

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

您可以在这里查看:http://webdriver.io/api/state/isExisting.html

client.isExisting(selector);

返回布尔值。所以你的代码应该是这样的:

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

重写它以使用对象

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

https://webdriver.io/docs/api/element/isExisting.html您使用5.0 webdriver.io 的4.0语法

检查https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md#v500-2018-12-20了解更多