MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / deselectByIndex

Method deselectByIndex

javascript/selenium-webdriver/lib/select.js:394–422  ·  view source on GitHub ↗

* * @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)

Source from the content-addressed store, hash-verified

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 *

Callers

nothing calls this directly

Calls 7

isMultipleMethod · 0.95
tagNameMethod · 0.80
findElementsMethod · 0.65
getAttributeMethod · 0.65
toStringMethod · 0.65
isSelectedMethod · 0.65
clickMethod · 0.65

Tested by

no test coverage detected