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
dont raise exception from click action
Nick Sweetingd5d341f22971
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 46f818d2d..26ae00991 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -144,6 +144,7 @@ class Controller(Generic[Context]):return ActionResult(extracted_content=f'Element with index {params.index} does not exist. Page has {len(selector_map)} interactive elements (indices 0-{max_index}). State has been refreshed - please use the updated element indices.',include_in_memory=True,+ success=False,)element_node = await browser_session.get_dom_element_by_index(params.index)@@ -153,7 +154,7 @@ class Controller(Generic[Context]):if await browser_session.find_file_upload_element_by_index(params.index) is not None:msg = f'Index {params.index} - has an element which opens file upload dialog. To upload files please use a specific function to upload files 'logger.info(msg)- return ActionResult(extracted_content=msg, include_in_memory=True)+ return ActionResult(extracted_content=msg, include_in_memory=True, success=False)msg = None@@ -178,10 +179,12 @@ class Controller(Generic[Context]):# Page navigated during click - refresh state and return itlogger.info('Page context changed during click, refreshing state...')await browser_session.get_state_summary(cache_clickable_elements_hashes=True)- return ActionResult(error='Page navigated during click. Refreshed state provided.', include_in_memory=True)+ return ActionResult(+ error='Page navigated during click. Refreshed state provided.', include_in_memory=True, success=False+ )else:logger.warning(f'Element not clickable with index {params.index} - most likely the page changed')- return ActionResult(error=error_msg)+ return ActionResult(error=error_msg, success=False)@self.registry.action('Input text into a input interactive element',diff --git a/tests/ci/test_controller.py b/tests/ci/test_controller.pyindex 5ccdd8bad..7a6384877 100644--- a/tests/ci/test_controller.py+++ b/tests/ci/test_controller.py@@ -268,7 +268,7 @@ class TestControllerIntegration:async def test_error_handling(self, controller, browser_session):"""Test error handling when an action fails."""# Create an action with an invalid index- invalid_action = {'click_element_by_index': ClickElementAction(index=9999)}+ invalid_action = {'click_element_by_index': ClickElementAction(index='abc')} # wrong type, expects a numberclass ClickActionModel(ActionModel):click_element_by_index: ClickElementAction | None = None