webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
26 lines (19 loc) • 778 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = selectByIndex;
var _utils = require("../../utils");
async function selectByIndex(index) {
if (index < 0) {
throw new Error('Index needs to be 0 or any other positive number');
}
const optionElements = await this.findElementsFromElement(this.elementId, 'css selector', 'option');
if (optionElements.length === 0) {
throw new Error('Select element doesn\'t contain any option element');
}
if (optionElements.length - 1 < index) {
throw new Error(`Option with index "${index}" not found. Select element only contains ${optionElements.length} option elements`);
}
return this.elementClick((0, _utils.getElementFromResponse)(optionElements[index]));
}