refactor select option logic (#3408)

This commit is contained in:
LawyZheng
2025-09-11 13:10:02 +08:00
committed by GitHub
parent f582f84c95
commit a5c25b5f7f

View File

@@ -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)))