webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
20 lines (15 loc) • 732 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = selectByAttribute;
var _utils = require("../../utils");
async function selectByAttribute(attribute, value) {
value = typeof value === 'number' ? value.toString() : value;
const normalized = `[normalize-space(@${attribute.trim()}) = "${value.trim()}"]`;
const optionElement = await this.findElementFromElement(this.elementId, 'xpath', `./option${normalized}|./optgroup/option${normalized}`);
if (optionElement && optionElement.error === 'no such element') {
throw new Error(`Option with attribute "${attribute}=${value}" not found.`);
}
return this.elementClick((0, _utils.getElementFromResponse)(optionElement));
}