Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Simplify input text
Magnus Müllerc452f9332753
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.pyindex 18899914a..a61934c60 100644--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@ -943,23 +943,18 @@ class BrowserContext:raise BrowserError(f'Element: {repr(element_node)} not found')# Ensure element is ready for input- await element_handle.wait_for_element_state('stable', timeout=2000)- await element_handle.scroll_into_view_if_needed(timeout=2100)+ await element_handle.wait_for_element_state('stable', timeout=1000)+ await element_handle.scroll_into_view_if_needed(timeout=1000)# Get element properties to determine input methodis_contenteditable = await element_handle.get_property('isContentEditable')# Different handling for contenteditable vs input fields- try:- if await is_contenteditable.json_value():- await element_handle.evaluate('el => el.textContent = ""')- await element_handle.type(text, delay=5)- else:- await element_handle.fill(text)- except Exception:- logger.debug('Could not type text into element. Trying to click and type.')- await element_handle.click()+ if await is_contenteditable.json_value():+ await element_handle.evaluate('el => el.textContent = ""')await element_handle.type(text, delay=5)+ else:+ await element_handle.fill(text)except Exception as e:logger.debug(f'Failed to input text into element: {repr(element_node)}. Error: {str(e)}')