* * @param {Number} index index of option element to deselect * Deselect the option at the given index. * This is done by examining the "index" * attribute of an element, and not merely by counting. * @returns {Promise }
(index)
| 392 | * @returns {Promise<void>} |
| 393 | */ |
| 394 | async deselectByIndex(index) { |
| 395 | if (!(await this.isMultiple())) { |
| 396 | throw new Error('You may only deselect options of a multi-select') |
| 397 | } |
| 398 | |
| 399 | if (index < 0) { |
| 400 | throw new Error('Index needs to be 0 or any other positive number') |
| 401 | } |
| 402 | |
| 403 | let options = await this.element.findElements(By.tagName('option')) |
| 404 | |
| 405 | if (options.length === 0) { |
| 406 | throw new Error("Select element doesn't contain any option element") |
| 407 | } |
| 408 | |
| 409 | if (options.length - 1 < index) { |
| 410 | throw new Error( |
| 411 | `Option with index "${index}" not found. Select element only contains ${options.length - 1} option elements`, |
| 412 | ) |
| 413 | } |
| 414 | |
| 415 | for (let option of options) { |
| 416 | if ((await option.getAttribute('index')) === index.toString()) { |
| 417 | if (await option.isSelected()) { |
| 418 | await option.click() |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * |
nothing calls this directly
no test coverage detected