Skip to content

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

Show invalid only when true

Magnus Müller27f0b50b43a5
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.py
index 548e17814..7c990c04f 100644
--- a/browser_use/dom/serializer/serializer.py
+++ b/browser_use/dom/serializer/serializer.py
@@ -947,6 +947,10 @@ class DOMTreeSerializer:
if 'type' in attributes_to_include and attributes_to_include['type'].lower() == node.node_name.lower():
del attributes_to_include['type']
+ # Remove invalid attribute if it's false (only show when true)
+ if 'invalid' in attributes_to_include and attributes_to_include['invalid'].lower() == 'false':
+ del attributes_to_include['invalid']
+
attrs_to_remove_if_text_matches = ['aria-label', 'placeholder', 'title']
for attr in attrs_to_remove_if_text_matches:
if attributes_to_include.get(attr) and attributes_to_include.get(attr, '').strip().lower() == text.strip().lower():