fix input timeout (#569)
This commit is contained in:
@@ -8,7 +8,7 @@ import structlog
|
|||||||
from deprecation import deprecated
|
from deprecation import deprecated
|
||||||
from playwright.async_api import Locator, Page, TimeoutError
|
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 (
|
from skyvern.exceptions import (
|
||||||
EmptySelect,
|
EmptySelect,
|
||||||
ErrFoundSelectableElement,
|
ErrFoundSelectableElement,
|
||||||
@@ -53,7 +53,6 @@ from skyvern.webeye.scraper.scraper import ScrapedPage
|
|||||||
from skyvern.webeye.utils.dom import AbstractSelectDropdown, DomUtil, SkyvernElement
|
from skyvern.webeye.utils.dom import AbstractSelectDropdown, DomUtil, SkyvernElement
|
||||||
|
|
||||||
LOG = structlog.get_logger()
|
LOG = structlog.get_logger()
|
||||||
TEXT_INPUT_DELAY = 10 # 10ms between each character input
|
|
||||||
COMMON_INPUT_TAGS = {"input", "textarea", "select"}
|
COMMON_INPUT_TAGS = {"input", "textarea", "select"}
|
||||||
|
|
||||||
|
|
||||||
@@ -271,8 +270,7 @@ async def handle_input_text_action(
|
|||||||
if await skyvern_element.is_select2_dropdown():
|
if await skyvern_element.is_select2_dropdown():
|
||||||
return [ActionFailure(InputActionOnSelect2Dropdown(element_id=action.element_id))]
|
return [ActionFailure(InputActionOnSelect2Dropdown(element_id=action.element_id))]
|
||||||
|
|
||||||
locator = skyvern_element.locator
|
current_text = await get_input_value(skyvern_element.get_tag_name(), skyvern_element.get_locator())
|
||||||
current_text = await get_input_value(locator)
|
|
||||||
if current_text == action.text:
|
if current_text == action.text:
|
||||||
return [ActionSuccess()]
|
return [ActionSuccess()]
|
||||||
|
|
||||||
@@ -281,7 +279,7 @@ async def handle_input_text_action(
|
|||||||
text = get_actual_value_of_parameter_if_secret(task, action.text)
|
text = get_actual_value_of_parameter_if_secret(task, action.text)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await locator.clear(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
await skyvern_element.input_clear()
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
LOG.info("None input tag clear timeout", action=action)
|
LOG.info("None input tag clear timeout", action=action)
|
||||||
return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))]
|
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))]
|
return [ActionFailure(InvalidElementForTextInput(element_id=action.element_id, tag_name=tag_name))]
|
||||||
|
|
||||||
if tag_name not in COMMON_INPUT_TAGS:
|
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()]
|
return [ActionSuccess()]
|
||||||
|
|
||||||
# If the input is a text input, we type the text character by character
|
# 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
|
# 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()]
|
return [ActionSuccess()]
|
||||||
|
|
||||||
|
|
||||||
@@ -1091,8 +1089,7 @@ async def click_listbox_option(
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def get_input_value(locator: Locator) -> str | None:
|
async def get_input_value(tag_name: str, locator: Locator) -> str | None:
|
||||||
tag_name = await get_tag_name_lowercase(locator)
|
|
||||||
if tag_name in COMMON_INPUT_TAGS:
|
if tag_name in COMMON_INPUT_TAGS:
|
||||||
return await locator.input_value()
|
return await locator.input_value()
|
||||||
# for span, div, p or other tags:
|
# for span, div, p or other tags:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from enum import StrEnum
|
|||||||
import structlog
|
import structlog
|
||||||
from playwright.async_api import Frame, FrameLocator, Locator, Page
|
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 (
|
from skyvern.exceptions import (
|
||||||
ElementIsNotComboboxDropdown,
|
ElementIsNotComboboxDropdown,
|
||||||
ElementIsNotLabel,
|
ElementIsNotLabel,
|
||||||
@@ -28,6 +28,9 @@ from skyvern.webeye.scraper.scraper import ScrapedPage, get_combobox_options, ge
|
|||||||
|
|
||||||
LOG = structlog.get_logger()
|
LOG = structlog.get_logger()
|
||||||
|
|
||||||
|
TEXT_INPUT_DELAY = 10 # 10ms between each character input
|
||||||
|
TEXT_PRESS_MAX_LENGTH = 10
|
||||||
|
|
||||||
|
|
||||||
async def resolve_locator(
|
async def resolve_locator(
|
||||||
scrape_page: ScrapedPage, page: Page, frame: str, css: str
|
scrape_page: ScrapedPage, page: Page, frame: str, css: str
|
||||||
@@ -249,7 +252,22 @@ class SkyvernElement:
|
|||||||
async def input_sequentially(
|
async def input_sequentially(
|
||||||
self, text: str, default_timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
self, text: str, default_timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||||
) -> None:
|
) -> 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:
|
class DomUtil:
|
||||||
|
|||||||
Reference in New Issue
Block a user