Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

try fixing click_element_by_index auto-returning get_dropdown_options shortcut when clicking on dropdown

Nick Sweeting271b12c9dfad
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index f8e580139..81d63af29 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -278,7 +278,9 @@ class Controller(Generic[Context]):
if node is None:
raise ValueError(f'Element index {params.index} not found in DOM')
- event = browser_session.event_bus.dispatch(ClickElementEvent(node=node, while_holding_ctrl=params.while_holding_ctrl))
+ event = browser_session.event_bus.dispatch(
+ ClickElementEvent(node=node, while_holding_ctrl=params.while_holding_ctrl)
+ )
await event
# Wait for handler to complete and get any exception (None is expected on success)
await event.event_result(raise_if_any=True, raise_if_none=False)
@@ -294,9 +296,13 @@ class Controller(Generic[Context]):
# If it's a select dropdown error, automatically get the dropdown options
if 'dropdown' in str(e) and node:
try:
- return await get_dropdown_options(index=params.index, browser_session=browser_session)
+ return await get_dropdown_options(
+ params=GetDropdownOptionsAction(index=params.index), browser_session=browser_session
+ )
except Exception as dropdown_error:
- pass
+ logger.error(
+ f'Failed to get dropdown options as shortcut during click_element_by_index on dropdown: {type(dropdown_error).__name__}: {dropdown_error}'
+ )
return ActionResult(error=error_msg)