Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// we succeed if we get some elements
return !_.isEmpty(els);
});
} catch (err) {
if (err.message && err.message.match(/Condition unmet/)) {
// condition was not met setting res to empty array
els = [];
} else {
throw err;
}
}
if (mult) {
return els;
}
if (_.isEmpty(els)) {
throw new errors.NoSuchElementError();
}
return els;
};
try {
await this.implicitWaitForCondition(doFind);
} catch (err) {
if (err.message && _.isFunction(err.message.match) && err.message.match(/Condition unmet/)) {
// condition was not met setting res to empty array
element = [];
} else {
throw err;
}
}
if (many) {
return element;
} else {
if (!element || _.size(element) === 0) {
throw new errors.NoSuchElementError();
}
return element;
}
};
try {
await this.implicitWaitForCondition(doFind);
} catch (err) {
if (err.message && err.message.match(/Condition unmet/)) {
// condition was not met setting res to empty array
res = [];
} else {
throw err;
}
}
if (mult) {
return res;
} else {
if (!res || _.size(res) === 0) {
throw new errors.NoSuchElementError();
}
return res;
}
};
await this.implicitWaitForCondition(doFind);
} catch (err) {
if (err.message && err.message.match(/Condition unmet/)) {
// only get here if we are looking for multiple elements
// condition was not met setting res to empty array
element = [];
} else {
throw err;
}
}
if (mult) {
return element;
}
if (_.isEmpty(element)) {
throw new errors.NoSuchElementError();
}
return element;
};
it('should throw NoSuchElementError if element does not exist', async function () {
driver.doFindElementOrEls.throws(new errors.NoSuchElementError());
await driver.findElOrEls('xpath', '//*[1]', false)
.should.be.rejectedWith(errors.NoSuchElementError);
});
it('should fails if locator strategy is not valid', async function () {
commands.keys = async function keys (keys) {
if (!this.isWebContext()) {
throw new errors.UnknownError('Command should be proxied to WDA');
}
let el = util.unwrapElement(await this.active());
if (_.isEmpty(el)) {
throw new errors.NoSuchElementError();
}
await this.setValue(keys, el);
};
commands.keys = async function keys (keys) {
if (this.isWebContext()) {
let el = await this.active();
if (_.isUndefined(el.ELEMENT)) {
throw new errors.NoSuchElementError();
}
await this.setValue(keys, el.ELEMENT);
} else {
if (_.isArray(keys)) {
keys = keys.join('');
}
if (!_.isString(keys)) {
keys = keys.toString();
}
keys = util.escapeSpecialChars(keys, "'");
let command = `au.sendKeysToActiveElement('${keys}')`;
await this.uiAutoClient.sendCommand(command);
}
};
if (!_.isEmpty(elements)) {
res.push(...elements);
}
} else {
let element = await this.uiAutoClient.sendCommand(command);
if (element) {
return element;
}
}
}
if (mult) {
return res;
}
throw new errors.NoSuchElementError();
};