SeleniumHQ/selenium · error · Error
You may only deselect options of a multi-select
Error message
You may only deselect options of a multi-select
What it means
Thrown by deselectByVisibleText() when the select is not a multi-select. Unlike deselectAll (error 91), this guard correctly uses `await this.isMultiple()`, so it fires reliably. The method also expects the text to match an option (it uses findElement which throws NoSuchElementError if absent). Generic Error for the multi-select check.
Source
Thrown at javascript/selenium-webdriver/lib/select.js:370
}
const options = await this.getOptions()
for (let option of options) {
if (await option.isSelected()) {
await option.click()
}
}
}
/**
*
* @param {string|Number}text text of option to deselect
* @returns {Promise<void>}
*/
async deselectByVisibleText(text) {
if (!(await this.isMultiple())) {
throw new Error('You may only deselect options of a multi-select')
}
/**
* convert value into string
*/
text = typeof text === 'number' ? text.toString() : text
const optionElement = await this.element.findElement(
By.xpath('.//option[normalize-space(.) = ' + escapeQuotes(text) + ']'),
)
if (await optionElement.isSelected()) {
await optionElement.click()
}
}
/**
*
* @param {Number} index index of option element to deselectView on GitHub (pinned to aa36b38e69)
Solutions
- Guard before calling: if (await sel.isMultiple()) await sel.deselectByVisibleText(t).
- Confirm the <select> has the multiple attribute in the page.
- Wrap in try/catch and treat this as a no-op for single selects if appropriate.
- Use a Select helper that branches on isMultiple().
Example fix
// before
await sel.deselectByVisibleText('X'); // single-select -> throws
// after
if (await sel.isMultiple()) {
await sel.deselectByVisibleText('X');
} else {
// single-select: deselect by picking a different/blank option
} Defensive patterns
Strategy: validation
Validate before calling
async function safeDeselectByText(sel, text) {
if (!(await sel.isMultiple())) throw new Error('requires multi-select');
await sel.deselectByVisibleText(text);
} Type guard
async function isMultiSelect(sel) {
return Boolean(await sel.isMultiple());
} Try / catch
try {
await sel.deselectByVisibleText(t);
} catch (e) {
if (/multi-select/.test(e.message)) { /* no-op for single selects */ }
else throw e;
} Prevention
- Branch all deselect* calls on await sel.isMultiple().
- Confirm the multiple attribute on the element for dropdowns you expect to be multi.
- Centralize deselect logic in a Select helper.
When it happens
Trigger: Calling deselectByVisibleText on a <select> without the multiple attribute. A single-select cannot have a 'deselected' state in the multi-select sense, so the operation is rejected up front.
Common situations: Generic form helpers; test code reused across single and multi selects; assuming a dropdown is multi because it visually allows clearing.
Related errors
- You may only deselect all options of a multi-select
- Element must not be null. Please provide a valid <select> el
- Index needs to be 0 or any other positive number
- Select only works on <select> elements, not on {webelement.t
- You may only deselect all options of a multi-select
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/046aa0768b894f7e.
Report an issue: GitHub.