Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Remove index return to avoid wrong index clicks
Magnus Müllerd1f33c0c5e36
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.pyindex dc7fcd241..180a5dedb 100644--- a/browser_use/browser/watchdogs/default_action_watchdog.py+++ b/browser_use/browser/watchdogs/default_action_watchdog.py@@ -1912,7 +1912,7 @@ class DefaultActionWatchdog(BaseWatchdog):self.logger.error(msg)raise BrowserError(message=msg, long_term_memory=msg)except Exception as e:- msg = f'Failed to get dropdown options for element with index {index_for_logging}'+ msg = 'Failed to get dropdown options'error_msg = f'{msg}: {str(e)}'self.logger.error(error_msg)raise BrowserError(diff --git a/browser_use/tools/service.py b/browser_use/tools/service.pyindex 19c37cca2..9caf2d7b3 100644--- a/browser_use/tools/service.py+++ b/browser_use/tools/service.py@@ -293,7 +293,7 @@ class Tools(Generic[Context]):await event# Wait for handler to complete and get any exception or metadataclick_metadata = await event.event_result(raise_if_any=True, raise_if_none=False)- memory = f'Clicked element with index {params.index}'+ memory = 'Clicked element'if params.while_holding_ctrl:memory += ' and opened in new tab'diff --git a/tests/ci/test_browser_event_ClickElementEvent.py b/tests/ci/test_browser_event_ClickElementEvent.pyindex 08265ac98..6a8b62684 100644--- a/tests/ci/test_browser_event_ClickElementEvent.py+++ b/tests/ci/test_browser_event_ClickElementEvent.py@@ -188,9 +188,7 @@ class TestClickElementEvent:result_text = result.extracted_content or result.long_term_memory# Core logic validation: Verify click was successfulassert result_text is not None- assert f'Clicked element with index {button_index}' in result_text, (- f'Expected click confirmation in result content, got: {result_text}'- )+ assert 'Clicked element' in result_text, f'Expected click confirmation in result content, got: {result_text}'# Note: The click action doesn't include button text in the result, only the index# Verify the click actually had an effect on the page using CDP@@ -262,9 +260,7 @@ class TestClickElementEvent:assert isinstance(result, ActionResult)result_text = result.extracted_content or result.long_term_memoryassert result_text is not None- assert f'Clicked element with index {link_index}' in result_text, (- f'Expected click confirmation in result content, got: {result_text}'- )+ assert 'Clicked element' in result_text, f'Expected click confirmation in result content, got: {result_text}'# Verify that a new tab was openedtabs = await browser_session.get_tabs()