ifx chain click bug (#576)

This commit is contained in:
LawyZheng
2024-07-11 02:45:13 +08:00
committed by GitHub
parent da66d66132
commit 0ddda3f481
2 changed files with 23 additions and 2 deletions

View File

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

View File

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