From 800c030e5c453edf35675c1337dc761ef17fd051 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Wed, 6 Aug 2025 23:15:59 +0800 Subject: [PATCH] do not clear input when empty (#3114) --- skyvern/webeye/actions/handler.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index 5b1534e4..879213cf 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -1086,8 +1086,21 @@ async def handle_input_text_action( exc_info=True, ) + # TODO: some elements are supported to use `locator.press_sequentially()` to fill in the data + # we need find a better way to detect the attribute in the future + class_name: str | None = await skyvern_element.get_attr("class") + if class_name and "blinking-cursor" in class_name: + if is_totp_value: + text = generate_totp_value(task=task, parameter=action.text) + await skyvern_element.press_fill(text=text) + return [ActionSuccess()] + # `Locator.clear()` on a spin button could cause the cursor moving away, and never be back - if not await skyvern_element.is_spinbtn_input(): + # run `Locator.clear()` when: + # 1. the element is not a spin button + # 1.1. the element has a value attribute + # 1.2. the element is not common input tag + if not await skyvern_element.is_spinbtn_input() and (current_text or (tag_name not in COMMON_INPUT_TAGS)): try: await skyvern_element.input_clear() except TimeoutError: @@ -1095,17 +1108,7 @@ async def handle_input_text_action( return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))] except Exception: LOG.warning("Failed to clear the input field", action=action, exc_info=True) - - # TODO: some elements are supported to use `locator.press_sequentially()` to fill in the data - # we need find a better way to detect the attribute in the future - class_name: str | None = await skyvern_element.get_attr("class") - if not class_name or "blinking-cursor" not in class_name: - return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))] - - if is_totp_value: - text = generate_totp_value(task=task, parameter=action.text) - await skyvern_element.press_fill(text=text) - return [ActionSuccess()] + return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))] # wait 2s for blocking element to show up await asyncio.sleep(2)