Webdriver.io: isExisting().then() 不是函数
Webdriver.io: isExisting().then() is not a function
我想检查是否有注销元素。如果它存在,我想通过单击此元素来注销:
browser.isExisting('.logout').then(function() {
browser.click('.logout');
});
但这给了我一个 Uncaught TypeError: browser.isExisting(...).then is not a function
-错误。
你可以看这里:http://webdriver.io/api/state/isExisting.html
client.isExisting(selector);
Returns 布尔值。
所以你的代码应该是这样的:
browser.isExisting('.logout').then(function(exist) {
if (exist) {
browser.click('.logout');
}
});
如果您使用的版本 <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 ), and you would need to rewrite a bit. http://webdriver.io/api/utility/waitForExist.html
像这样
var logout = browser.element('.logout');
logout.waitForExist(5000);
browser.click('.logout');
重写它以使用对象
browser.$('.logout').isExisting().then(function() {
browser.click('.logout');
});
https://webdriver.io/docs/api/element/isExisting.html
您将 4.0 语法用于 5.0 webdriver.io
查看https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md#v500-2018-12-20了解更多
我想检查是否有注销元素。如果它存在,我想通过单击此元素来注销:
browser.isExisting('.logout').then(function() {
browser.click('.logout');
});
但这给了我一个 Uncaught TypeError: browser.isExisting(...).then is not a function
-错误。
你可以看这里:http://webdriver.io/api/state/isExisting.html
client.isExisting(selector);
Returns 布尔值。 所以你的代码应该是这样的:
browser.isExisting('.logout').then(function(exist) {
if (exist) {
browser.click('.logout');
}
});
如果您使用的版本 <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 ), and you would need to rewrite a bit. http://webdriver.io/api/utility/waitForExist.html
像这样
var logout = browser.element('.logout');
logout.waitForExist(5000);
browser.click('.logout');
重写它以使用对象
browser.$('.logout').isExisting().then(function() {
browser.click('.logout');
});
https://webdriver.io/docs/api/element/isExisting.html 您将 4.0 语法用于 5.0 webdriver.io
查看https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md#v500-2018-12-20了解更多