From a5c25b5f7fd5d9175aaec256b1b2cd2b37a40135 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Thu, 11 Sep 2025 13:10:02 +0800 Subject: [PATCH] refactor select option logic (#3408) --- skyvern/webeye/actions/handler.py | 47 +++++++++++++------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index ac7eda1e..9676c726 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -29,6 +29,7 @@ from skyvern.exceptions import ( FailedToFetchSecret, FailToClick, FailToSelectByIndex, + FailToSelectByLabel, FailToSelectByValue, IllegitComplete, ImaginaryFileUrl, @@ -3446,20 +3447,6 @@ async def normal_select( index: int | None = json_response.get("index") value: str | None = json_response.get("value") - try: - await locator.click( - timeout=settings.BROWSER_ACTION_TIMEOUT_MS, - ) - except Exception as e: - LOG.info( - "Failed to click before select action", - exc_info=True, - action=action, - locator=locator, - ) - action_result.append(ActionFailure(e)) - return action_result - if not is_success and value is not None: try: # click by value (if it matches) @@ -3478,6 +3465,24 @@ async def normal_select( locator=locator, ) + if not is_success and value is not None: + try: + # click by label (if it matches) + await locator.select_option( + label=value, + timeout=settings.BROWSER_ACTION_TIMEOUT_MS, + ) + is_success = True + action_result.append(ActionSuccess()) + except Exception: + action_result.append(ActionFailure(FailToSelectByLabel(action.element_id))) + LOG.info( + "Failed to take select action by label", + exc_info=True, + action=action, + locator=locator, + ) + if not is_success and index is not None: if index >= len(skyvern_element.get_options()): action_result.append(ActionFailure(OptionIndexOutOfBound(action.element_id))) @@ -3504,20 +3509,6 @@ async def normal_select( locator=locator, ) - try: - await locator.click( - timeout=settings.BROWSER_ACTION_TIMEOUT_MS, - ) - except Exception as e: - LOG.info( - "Failed to click after select action", - exc_info=True, - action=action, - locator=locator, - ) - action_result.append(ActionFailure(e)) - return action_result - if len(action_result) == 0: action_result.append(ActionFailure(EmptySelect(element_id=action.element_id)))