Skip to content

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

For input also make sure its the top element

Magnus Müller726301f3fcfa
diff --git a/browser_use/browser/watchdogs/default_action_watchdog.py b/browser_use/browser/watchdogs/default_action_watchdog.py
index cefc85e46..24365d517 100644
--- a/browser_use/browser/watchdogs/default_action_watchdog.py
+++ b/browser_use/browser/watchdogs/default_action_watchdog.py
@@ -1122,11 +1122,20 @@ class DefaultActionWatchdog(BaseWatchdog):
if coords:
center_x = coords.x + coords.width / 2
center_y = coords.y + coords.height / 2
- input_coordinates = {'input_x': center_x, 'input_y': center_y}
- self.logger.debug(f'Using unified coordinates: x={center_x:.1f}, y={center_y:.1f}')
+
+ # Check for occlusion before using coordinates for focus
+ is_occluded = await self._check_element_occlusion(backend_node_id, center_x, center_y, cdp_session)
+
+ if is_occluded:
+ self.logger.debug('🚫 Input element is occluded, skipping coordinate-based focus')
+ input_coordinates = None # Force fallback to CDP-only focus
+ else:
+ input_coordinates = {'input_x': center_x, 'input_y': center_y}
+ self.logger.debug(f'Using unified coordinates: x={center_x:.1f}, y={center_y:.1f}')
else:
input_coordinates = None
self.logger.debug('No coordinates found for element')
+
# Ensure we have a valid object_id before proceeding
if not object_id:
raise ValueError('Could not get object_id for element')