Skip to content

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

fix: convert xpath with colons in element names

Mike Wang8786c1d56c79
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.py
index d005be4ea..0fb40ae6f 100644
--- a/browser_use/browser/context.py
+++ b/browser_use/browser/context.py
@@ -879,9 +879,18 @@ class BrowserContext:
if not part:
continue
+ # Handle custom elements with colons by escaping them
+ if ':' in part and '[' not in part:
+ base_part = part.replace(':', r'\:')
+ css_parts.append(base_part)
+ continue
+
# Handle index notation [n]
if '[' in part:
base_part = part[: part.find('[')]
+ # Handle custom elements with colons in the base part
+ if ':' in base_part:
+ base_part = base_part.replace(':', r'\:')
index_part = part[part.find('[') :]
# Handle multiple indices