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.
-
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
3 Answers
Reset to default 2If 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条)