SeleniumHQ/selenium · error · UnexpectedAlertOpenError
${message}
Error message
${message} What it means
Thrown by checkLegacyResponse() in error.js when a legacy Selenium 2.0 wire protocol response has a non-zero numeric `status` and the `value` is an object containing a `message`. The error constructor is resolved from LEGACY_ERROR_CODE_TO_TYPE; for UnexpectedAlertOpenError it also extracts the alert text. The message comes from value.message.
Source
Thrown at javascript/selenium-webdriver/lib/error.js:560
// Handle the legacy Selenium error response format.
if (isObject(responseObj) && typeof responseObj.status === 'number' && responseObj.status !== 0) {
const { status, value } = responseObj
let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError
if (!value || typeof value !== 'object') {
throw new ctor(value + '')
} else {
let message = value['message'] + ''
if (ctor !== UnexpectedAlertOpenError) {
throw new ctor(message)
}
let text = ''
if (value['alert'] && typeof value['alert']['text'] === 'string') {
text = value['alert']['text']
}
throw new UnexpectedAlertOpenError(message, text)
}
}
return responseObj
}
// PUBLIC API
module.exports = {
ErrorCode,
WebDriverError,
DetachedShadowRootError,
ElementClickInterceptedError,
ElementNotInteractableError,
ElementNotSelectableError,
InsecureCertificateError,
InvalidArgumentError,
InvalidCookieDomainError,View on GitHub (pinned to aa36b38e69)
Solutions
- Upgrade to a W3C-compliant Selenium server/Grid (Selenium 3.141+ in W3C mode or Selenium 4+).
- Handle unexpected alerts proactively using the Alert API: driver.switchTo().alert().dismiss().
- Read value.message and value.alert.text in the caught error for root-cause diagnosis.
- Set pageLoadStrategy or unexpectedAlertBehavior capability to control alert handling.
Defensive patterns
Strategy: try-catch
Try / catch
try {
// ... execute command ...
} catch (e) {
if (e instanceof UnexpectedAlertOpenError) {
console.warn('Unexpected alert:', e.text || '(no text)')
await driver.switchTo().alert().dismiss()
// retry the command if appropriate
}
throw e
} Prevention
- Upgrade to a W3C-compliant Selenium server (Selenium 4+) to avoid legacy protocol responses.
- Set the unexpectedAlertBehavior capability ('accept', 'dismiss', or 'ignore') to control alert handling.
- Use driver.switchTo().alert() to handle expected alerts before they block commands.
- Watch for the UnexpectedAlertOpenError type specifically and extract alert text for diagnosis.
When it happens
Trigger: Connecting to a legacy Selenium 2 server/endpoint that returns {status, value:{message,...}} format. An unexpected JavaScript alert is open when a command executes, and the server uses the legacy protocol. A third-party service using the legacy wire protocol returns an error.
Common situations: Using old Selenium server/Grid versions (pre-W3C); third-party testing services with legacy protocol support; tests that trigger unexpected browser alerts; mixed protocol environments.
Related errors
- Unknown error: ${JSON.stringify(data)}
- {error}: {response['message']}
- Params must be an instance of CookieFilter. Received:'${cook
- Cannot locate an element with provided parameters
- Custom locator did not return a WebElement
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/c2073ac3e2eb9ba3.
Report an issue: GitHub.