handler_utils.input_sequentially (#2722)
This commit is contained in:
@@ -11,7 +11,7 @@ import structlog
|
||||
from playwright.async_api import ElementHandle, Frame, FrameLocator, Locator, Page, TimeoutError
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import SKYVERN_ID_ATTR
|
||||
from skyvern.constants import SKYVERN_ID_ATTR, TEXT_INPUT_DELAY
|
||||
from skyvern.exceptions import (
|
||||
ElementIsNotLabel,
|
||||
InteractWithDisabledElement,
|
||||
@@ -24,15 +24,13 @@ from skyvern.exceptions import (
|
||||
NoneFrameError,
|
||||
SkyvernException,
|
||||
)
|
||||
from skyvern.webeye.actions import handler_utils
|
||||
from skyvern.webeye.scraper.scraper import IncrementalScrapePage, ScrapedPage, json_to_html, trim_element
|
||||
from skyvern.webeye.utils.page import SkyvernFrame
|
||||
|
||||
LOG = structlog.get_logger()
|
||||
COMMON_INPUT_TAGS = {"input", "textarea", "select"}
|
||||
|
||||
TEXT_INPUT_DELAY = 10 # 10ms between each character input
|
||||
TEXT_PRESS_MAX_LENGTH = 20
|
||||
|
||||
|
||||
async def resolve_locator(scrape_page: ScrapedPage, page: Page, frame: str, css: str) -> tuple[Locator, Page | Frame]:
|
||||
iframe_path: list[str] = []
|
||||
@@ -574,14 +572,7 @@ class SkyvernElement:
|
||||
await self.get_locator().focus(timeout=timeout)
|
||||
|
||||
async def input_sequentially(self, text: str, default_timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
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.input_fill(text[: length - TEXT_PRESS_MAX_LENGTH])
|
||||
text = text[length - TEXT_PRESS_MAX_LENGTH :]
|
||||
|
||||
await self.press_fill(text, timeout=default_timeout)
|
||||
await handler_utils.input_sequentially(self.get_locator(), text, timeout=default_timeout)
|
||||
|
||||
async def press_key(self, key: str, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().press(key=key, timeout=timeout)
|
||||
|
||||
Reference in New Issue
Block a user