fallback to input when input selection failed (#1393)

This commit is contained in:
LawyZheng
2024-12-16 23:34:21 +08:00
committed by GitHub
parent 245cd1ca2f
commit e2f886d9a3
2 changed files with 34 additions and 8 deletions

View File

@@ -545,3 +545,10 @@ class FailedToParseActionInstruction(SkyvernException):
class UnsupportedTaskType(SkyvernException): class UnsupportedTaskType(SkyvernException):
def __init__(self, task_type: str): def __init__(self, task_type: str):
super().__init__(f"Not supported task type [{task_type}]") super().__init__(f"Not supported task type [{task_type}]")
class InteractWithDropdownContainer(SkyvernException):
def __init__(self, element_id: str):
super().__init__(
f"Select on the dropdown container instead of the option, try again with another element. element_id={element_id}"
)

View File

@@ -31,6 +31,7 @@ from skyvern.exceptions import (
IllegitComplete, IllegitComplete,
ImaginaryFileUrl, ImaginaryFileUrl,
InteractWithDisabledElement, InteractWithDisabledElement,
InteractWithDropdownContainer,
InvalidElementForTextInput, InvalidElementForTextInput,
MissingElement, MissingElement,
MissingElementDict, MissingElementDict,
@@ -571,15 +572,27 @@ async def handle_input_text_action(
task=task, task=task,
target_value=text, target_value=text,
) )
if result is not None: if result is not None and result.success:
return [result] return [result]
LOG.info(
"It might not be a selectable auto-completion input, exit the custom selection mode", if result is None:
task_id=task.task_id, LOG.info(
step_id=step.step_id, "It might not be a selectable auto-completion input, exit the custom selection mode",
element_id=skyvern_element.get_id(), task_id=task.task_id,
action=action, step_id=step.step_id,
) element_id=skyvern_element.get_id(),
action=action,
)
else:
LOG.warning(
"Custom selection returned an error, continue to input text",
task_id=task.task_id,
step_id=step.step_id,
element_id=skyvern_element.get_id(),
action=action,
err_msg=result.exception_message,
)
except Exception: except Exception:
await skyvern_element.scroll_into_view() await skyvern_element.scroll_into_view()
LOG.warning( LOG.warning(
@@ -1951,6 +1964,12 @@ async def select_from_dropdown(
try: try:
selected_element = await SkyvernElement.create_from_incremental(incremental_scraped, element_id) selected_element = await SkyvernElement.create_from_incremental(incremental_scraped, element_id)
if await selected_element.get_attr("role") == "listbox":
single_select_result.action_result = ActionFailure(
exception=InteractWithDropdownContainer(element_id=element_id)
)
return single_select_result
await selected_element.scroll_into_view() await selected_element.scroll_into_view()
await selected_element.get_locator().click(timeout=timeout) await selected_element.get_locator().click(timeout=timeout)
single_select_result.action_result = ActionSuccess() single_select_result.action_result = ActionSuccess()