/**
*
* Select option with a specific index.
*
*
:example.html
:selectByIndex.js
it('should demonstrate the selectByIndex command', function () {
var selectBox = $('#selectbox');
console.log(selectBox.getValue()); // returns "someValue0"
selectBox.selectByIndex(4);
console.log(selectBox.getValue()); // returns "someValue4"
});
*
*
* @alias browser.selectByIndex
* @param {String} selector select element that contains the options
* @param {Number} index option index
* @uses protocol/element, protocol/elementIdElements, protocol/elementIdClick
* @type action
*
*/
import { CommandError, RuntimeError } from '../utils/ErrorHandler'
let selectByIndex = function (selector, index) {
/*!
* negative index check
*/
if (index < 0) {
throw new CommandError('index needs to be 0 or any other positive number')
}
return this.element(selector).then((element) => {
/**
* check if element was found and throw error if not
*/
if (!element.value) {
throw new RuntimeError(7)
}
return this.elementIdElements(element.value.ELEMENT, '