Skip to content

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

Remove tag name on the end and > inbetween

Magnus Müller7792f6766dc5
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.py
index 86bbe0183..15396faff 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -141,12 +141,12 @@ class DOMElementNode(DOMBaseNode):
if text in attributes:
attributes.remove(text)
attributes_str = ';'.join(attributes)
+ line = f'[{node.highlight_index}]<{node.tag_name} '
+ if attributes_str:
+ line += f'{attributes_str}>'
if text:
- formatted_text.append(
- f'[{node.highlight_index}]<{node.tag_name} {attributes_str}>{text}</{node.tag_name}>'
- )
- else:
- formatted_text.append(f'[{node.highlight_index}]<{node.tag_name} {attributes_str}/>')
+ line += f'{text}>'
+ formatted_text.append(line)
# Process children regardless
for child in node.children: