Skip to content

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

Format interactive element

Magnus Müller11121179a40b
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.py
index 15396faff..05c597c62 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -143,9 +143,13 @@ class DOMElementNode(DOMBaseNode):
attributes_str = ';'.join(attributes)
line = f'[{node.highlight_index}]<{node.tag_name} '
if attributes_str:
- line += f'{attributes_str}>'
+ line += f'{attributes_str}'
if text:
- line += f'{text}>'
+ if attributes_str:
+ line += f'>{text}'
+ else:
+ line += f'{text}'
+ line += '/>'
formatted_text.append(line)
# Process children regardless