From 7c4284d05270e01e01d8209b74ae725ed9c220ee Mon Sep 17 00:00:00 2001 From: guybensimhon1 Date: Tue, 4 Mar 2025 12:34:49 +0200 Subject: [PATCH] Update isContentEditable handling to check readonly and disabled attributes - Retrieve tag name and isContentEditable property from element_handle. - Check for readonly and disabled attributes before inputting text. - Clear element's textContent regardless of element type. - Use element_handle.type() with delay for contenteditable or input elements if editable. - Fallback to element_handle.fill() for non-editable cases. --- browser_use/browser/context.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/browser_use/browser/context.py b/browser_use/browser/context.py index 44b7595d5..d005be4ea 100644 --- a/browser_use/browser/context.py +++ b/browser_use/browser/context.py @@ -1084,10 +1084,16 @@ class BrowserContext: pass # Get element properties to determine input method + tag_handle = await element_handle.get_property("tagName") + tag_name = (await tag_handle.json_value()).lower() is_contenteditable = await element_handle.get_property('isContentEditable') + readonly_handle = await element_handle.get_property("readOnly") + disabled_handle = await element_handle.get_property("disabled") - # Different handling for contenteditable vs input fields - if await is_contenteditable.json_value(): + readonly = await readonly_handle.json_value() if readonly_handle else False + disabled = await disabled_handle.json_value() if disabled_handle else False + + if (await is_contenteditable.json_value() or tag_name == 'input') and not (readonly or disabled): await element_handle.evaluate('el => el.textContent = ""') await element_handle.type(text, delay=5) else: