From 0ddda3f481ba352d05c2b2d3716d5b97e2f2e808 Mon Sep 17 00:00:00 2001 From: LawyZheng Date: Thu, 11 Jul 2024 02:45:13 +0800 Subject: [PATCH] ifx chain click bug (#576) --- skyvern/exceptions.py | 7 +++++++ skyvern/webeye/actions/handler.py | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/skyvern/exceptions.py b/skyvern/exceptions.py index 4ab7ad52..3477a458 100644 --- a/skyvern/exceptions.py +++ b/skyvern/exceptions.py @@ -421,3 +421,10 @@ class FailedToGetCurrentValueOfDropdown(SkyvernException): class HttpException(SkyvernException): def __init__(self, status_code: int, url: str, msg: str | None = None) -> None: super().__init__(f"HTTP Exception, status_code={status_code}, url={url}" + (f", msg={msg}" if msg else "")) + + +class WrongElementToUploadFile(SkyvernException): + def __init__(self, element_id: str): + super().__init__( + f"No file chooser dialog opens, so file can't be uploaded through element {element_id}. Please try to upload again with another element." + ) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index ce114edb..fc81968a 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -6,7 +6,7 @@ from typing import Any, Awaitable, Callable, List import structlog from deprecation import deprecated -from playwright.async_api import Locator, Page, TimeoutError +from playwright.async_api import FileChooser, Locator, Page, TimeoutError from skyvern.constants import REPO_ROOT_DIR from skyvern.exceptions import ( @@ -24,6 +24,7 @@ from skyvern.exceptions import ( MultipleElementsFound, NoSelectableElementFound, OptionIndexOutOfBound, + WrongElementToUploadFile, ) from skyvern.forge import app from skyvern.forge.prompts import prompt_engine @@ -712,7 +713,13 @@ async def chain_click( ) file = [] - fc_func = lambda fc: fc.set_files(files=file) # noqa: E731 + is_filechooser_trigger = False + + async def fc_func(fc: FileChooser) -> None: + await fc.set_files(files=file) + nonlocal is_filechooser_trigger + is_filechooser_trigger = True + page.on("filechooser", fc_func) LOG.info("Registered file chooser listener", action=action, path=file) @@ -795,6 +802,13 @@ async def chain_click( await asyncio.sleep(10) page.remove_listener("filechooser", fc_func) + if action.file_url and not is_filechooser_trigger: + LOG.warning( + "Action has file_url, but filechoose even hasn't been triggered. Upload file attempt seems to fail", + action=action, + ) + return [ActionFailure(WrongElementToUploadFile(action.element_id))] + async def normal_select( action: actions.SelectOptionAction,