fix input timeout (#569)

This commit is contained in:
LawyZheng
2024-07-10 00:04:03 +08:00
committed by GitHub
parent 19ed11d4d7
commit 6af581a7e4
2 changed files with 26 additions and 11 deletions

View File

@@ -8,7 +8,7 @@ import structlog
from deprecation import deprecated
from playwright.async_api import Locator, Page, TimeoutError
from skyvern.constants import INPUT_TEXT_TIMEOUT, REPO_ROOT_DIR
from skyvern.constants import REPO_ROOT_DIR
from skyvern.exceptions import (
EmptySelect,
ErrFoundSelectableElement,
@@ -53,7 +53,6 @@ from skyvern.webeye.scraper.scraper import ScrapedPage
from skyvern.webeye.utils.dom import AbstractSelectDropdown, DomUtil, SkyvernElement
LOG = structlog.get_logger()
TEXT_INPUT_DELAY = 10 # 10ms between each character input
COMMON_INPUT_TAGS = {"input", "textarea", "select"}
@@ -271,8 +270,7 @@ async def handle_input_text_action(
if await skyvern_element.is_select2_dropdown():
return [ActionFailure(InputActionOnSelect2Dropdown(element_id=action.element_id))]
locator = skyvern_element.locator
current_text = await get_input_value(locator)
current_text = await get_input_value(skyvern_element.get_tag_name(), skyvern_element.get_locator())
if current_text == action.text:
return [ActionSuccess()]
@@ -281,7 +279,7 @@ async def handle_input_text_action(
text = get_actual_value_of_parameter_if_secret(task, action.text)
try:
await locator.clear(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
await skyvern_element.input_clear()
except TimeoutError:
LOG.info("None input tag clear timeout", action=action)
return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))]
@@ -290,12 +288,12 @@ async def handle_input_text_action(
return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))]
if tag_name not in COMMON_INPUT_TAGS:
await locator.fill(text, timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
await skyvern_element.input_fill(text)
return [ActionSuccess()]
# If the input is a text input, we type the text character by character
# 3 times the time it takes to type the text so it has time to finish typing
await locator.press_sequentially(text, timeout=INPUT_TEXT_TIMEOUT)
await skyvern_element.input_sequentially(text=text)
return [ActionSuccess()]
@@ -1091,8 +1089,7 @@ async def click_listbox_option(
return False
async def get_input_value(locator: Locator) -> str | None:
tag_name = await get_tag_name_lowercase(locator)
async def get_input_value(tag_name: str, locator: Locator) -> str | None:
if tag_name in COMMON_INPUT_TAGS:
return await locator.input_value()
# for span, div, p or other tags:

View File

@@ -7,7 +7,7 @@ from enum import StrEnum
import structlog
from playwright.async_api import Frame, FrameLocator, Locator, Page
from skyvern.constants import INPUT_TEXT_TIMEOUT, SKYVERN_ID_ATTR
from skyvern.constants import SKYVERN_ID_ATTR
from skyvern.exceptions import (
ElementIsNotComboboxDropdown,
ElementIsNotLabel,
@@ -28,6 +28,9 @@ from skyvern.webeye.scraper.scraper import ScrapedPage, get_combobox_options, ge
LOG = structlog.get_logger()
TEXT_INPUT_DELAY = 10 # 10ms between each character input
TEXT_PRESS_MAX_LENGTH = 10
async def resolve_locator(
scrape_page: ScrapedPage, page: Page, frame: str, css: str
@@ -249,7 +252,22 @@ class SkyvernElement:
async def input_sequentially(
self, text: str, default_timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
) -> None:
await self.locator.press_sequentially(text, timeout=INPUT_TEXT_TIMEOUT)
length = len(text)
if length > TEXT_PRESS_MAX_LENGTH:
# if the text is longer than TEXT_PRESS_MAX_LENGTH characters, we will locator.fill in initial texts until the last TEXT_PRESS_MAX_LENGTH characters
# and then type the last TEXT_PRESS_MAX_LENGTH characters with locator.press_sequentially
await self.get_locator().fill(text[: length - TEXT_PRESS_MAX_LENGTH])
text = text[length - TEXT_PRESS_MAX_LENGTH :]
await self.get_locator().press_sequentially(text, delay=TEXT_INPUT_DELAY, timeout=default_timeout)
async def input_fill(
self, text: str, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
) -> None:
await self.get_locator().fill(text, timeout=timeout)
async def input_clear(self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) -> None:
await self.get_locator().clear(timeout=timeout)
class DomUtil: