SeleniumHQ/selenium · error · ValueError
Behavior can only be one of the following: dismiss, accept,
Error message
Behavior can only be one of the following: dismiss, accept, dismiss and notify, accept and notify, ignore
What it means
The unhandled_prompt_behavior property validates against the W3C-defined alert-handling behaviors: 'dismiss', 'accept', 'dismiss and notify', 'accept and notify', and 'ignore'. Any other value raises ValueError. Note the values are lowercase, space-separated, using 'and' (not '&').
Source
Thrown at py/selenium/webdriver/common/options.py:112
Args:
behavior: behavior to use when an alert is encountered
Returns:
Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
"""
def __init__(self, name):
self.name = name
def __get__(self, obj, cls):
return obj._caps.get(self.name)
def __set__(self, obj, value):
if value in ("dismiss", "accept", "dismiss and notify", "accept and notify", "ignore"):
obj.set_capability(self.name, value)
else:
raise ValueError(
"Behavior can only be one of the following: dismiss, accept, dismiss and notify, "
"accept and notify, ignore"
)
class _TimeoutsDescriptor:
"""How long the driver should wait for actions to complete before returning an error.
See:
- https://w3c.github.io/webdriver/#timeouts
Args:
timeouts: values in milliseconds for implicit wait, page load and script timeout
Returns:
Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
"""
View on GitHub (pinned to aa36b38e69)
Solutions
- Use one of the exact lowercase strings with spaces: 'dismiss', 'accept', 'dismiss and notify', 'accept and notify', 'ignore'.
- Replace underscores with spaces and use 'and' not '&'.
Example fix
# before options.unhandled_prompt_behavior = 'dismiss_and_notify' # raises # after options.unhandled_prompt_behavior = 'dismiss and notify'
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'dismiss','accept','dismiss and notify','accept and notify','ignore'}
if behavior not in ALLOWED:
raise ValueError(f'Invalid unhandled_prompt_behavior {behavior!r}')
options.unhandled_prompt_behavior = behavior Type guard
ALLOWED = {'dismiss','accept','dismiss and notify','accept and notify','ignore'}
def is_valid_prompt_behavior(v: str) -> bool:
return v in ALLOWED Try / catch
try:
options.unhandled_prompt_behavior = behavior
except ValueError:
options.unhandled_prompt_behavior = 'dismiss and notify' Prevention
- Remember values use spaces and 'and', not underscores or '&'.
- Validate against the constant set before assignment.
When it happens
Trigger: Setting options.unhandled_prompt_behavior to a value not in the allowed set, e.g. 'dismiss_and_notify', 'Accept', 'accept-and-notify', 'accept & notify', or 'default'.
Common situations: Using underscores instead of spaces ('dismiss_and_notify'). Using ampersands ('accept & notify'). Wrong casing. Confusing with a different driver's prompt-behavior vocabulary.
Related errors
- Strategy can only be one of the following: normal, eager, no
- Timeout keys can only be one of the following: implicit, pag
- no capabilities provided for merge
- Capability keys must be strings: ${typeof key}
- argument can not be null
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/6126bb0b5157ce37.
Report an issue: GitHub.