mirror of
https://github.com/browser-use/browser-use
synced 2026-05-13 17:56:35 +02:00
click by x,y coordinate fallback when main method fails
This commit is contained in:
@@ -1490,6 +1490,20 @@ class BrowserSession(BaseModel):
|
||||
except URLNotAllowedError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
# Final fallback - try clicking by coordinates if available
|
||||
if element_node.viewport_coordinates and element_node.viewport_coordinates.center:
|
||||
try:
|
||||
self.logger.warning(
|
||||
f'⚠️ Element click failed, falling back to coordinate click at ({element_node.viewport_coordinates.center.x}, {element_node.viewport_coordinates.center.y})'
|
||||
)
|
||||
await page.mouse.click(
|
||||
element_node.viewport_coordinates.center.x, element_node.viewport_coordinates.center.y
|
||||
)
|
||||
await page.wait_for_load_state()
|
||||
await self._check_and_handle_navigation(page)
|
||||
return None # Success
|
||||
except Exception as coord_e:
|
||||
self.logger.error(f'Coordinate click also failed: {type(coord_e).__name__}: {coord_e}')
|
||||
raise Exception(f'Failed to click element: {type(e).__name__}: {e}')
|
||||
|
||||
except URLNotAllowedError as e:
|
||||
|
||||
@@ -139,7 +139,12 @@ class Controller(Generic[Context]):
|
||||
selector_map = await browser_session.get_selector_map()
|
||||
|
||||
if params.index not in selector_map:
|
||||
raise Exception(f'Element with index {params.index} does not exist - retry or use alternative actions')
|
||||
# Return informative message with the new state instead of error
|
||||
max_index = max(selector_map.keys()) if selector_map else -1
|
||||
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,
|
||||
)
|
||||
|
||||
element_node = await browser_session.get_dom_element_by_index(params.index)
|
||||
initial_pages = len(browser_session.tabs)
|
||||
|
||||
Reference in New Issue
Block a user