Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Type into the nested input when a card field's wrapper isn't directly fillable (SKY-12448) (#7773)
LawyZheng22f23de780d1
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.pyindex 6329646b4..6cc3a26ef 100644--- a/skyvern/webeye/actions/handler.py+++ b/skyvern/webeye/actions/handler.py@@ -3769,6 +3769,39 @@ async def _is_commit_required_combobox(skyvern_element: SkyvernElement) -> bool:return _attr_indicates_aria_invalid(aria_invalid)+async def _retarget_wrapper_for_input_text(+ dom: DomUtil,+ skyvern_element: SkyvernElement,+ action: actions.InputTextAction,+) -> SkyvernElement | None:+ # Normalize a secure card-entry wrapper (<div>/<iframe>) to its single unambiguous nested <input>+ # so the pipeline below (including wait_until_enabled) runs against the real field. include_disabled+ # keeps a transiently-disabled unique input as the target -- the downstream enabled-wait then waits on+ # it. Sibling/decoy inputs make the helper bail, so card data can never land in a CVV or decoy field.+ child_id = skyvern_element.find_deepest_interactable_descendant_in_single_chain(include_disabled=True)+ if not child_id:+ return None+ child_element = await dom.safe_get_skyvern_element_by_id(child_id)+ if child_element is None:+ return None+ if await child_element.has_hidden_attr():+ return None+ # This path can carry card data; has_hidden_attr only reads attributes, so a candidate that went+ # CSS-hidden (display:none/visibility:hidden) between scrape and action would slip through. Fail+ # closed on rendered visibility before committing the retarget.+ if not await child_element.is_visible():+ return None+ if not await child_element.supports_text_input():+ return None+ LOG.info(+ "Re-targeting input_text from wrapper to nested interactable input",+ parent_id=skyvern_element.get_id(),+ child_id=child_id,+ )+ action.element_id = child_id+ return child_element++@traced(name="skyvern.agent.action.input_text")async def handle_input_text_action(action: actions.InputTextAction,@@ -3829,6 +3862,24 @@ async def handle_input_text_action(dom = DomUtil(scraped_page, page)skyvern_element = await dom.get_skyvern_element_by_id(action.element_id)++ # Normalize a wrapper target -- a visible <div>/<iframe> whose real editable <input> is nested one+ # frame deeper (e.g. cross-origin card-entry widgets) -- to that input so the pipeline below runs+ # against the real field. Selectable targets are left for the select-option conversion below.+ # Fail-closed: sibling/decoy descendants make the single-chain helper bail, so card data can never+ # land in a CVV or anti-autofill decoy field.+ can_input_text = await skyvern_element.supports_text_input()+ # Cache the wrapper's dynamic hidden state read for the retarget gate; the reject block below reuses it+ # (the target is unchanged when no retarget occurs) instead of a second dynamic get_attribute round-trip.+ target_hidden: bool | None = None+ if not can_input_text:+ target_hidden = await skyvern_element.has_hidden_attr()+ if not target_hidden and not await skyvern_element.get_selectable():+ retargeted_element = await _retarget_wrapper_for_input_text(dom, skyvern_element, action)+ if retargeted_element is not None:+ skyvern_element = retargeted_element+ can_input_text = True+skyvern_frame = await SkyvernFrame.create_instance(skyvern_element.get_frame())incremental_scraped = IncrementalScrapePage(skyvern_frame=skyvern_frame, engine_selection=resolve_engine_selection_for_task(task)@@ -3897,8 +3948,9 @@ async def handle_input_text_action(skyvern_element=skyvern_element,step=step,)- if not await skyvern_element.supports_text_input():- if await skyvern_element.has_hidden_attr():+ if not can_input_text:+ target_is_hidden = target_hidden if target_hidden is not None else await skyvern_element.has_hidden_attr()+ if target_is_hidden:return [ActionFailure(InputToInvisibleElement(skyvern_element.get_id()), stop_execution_on_failure=False)]is_date_related = input_or_select_context is not None and input_or_select_context.is_date_related is True@@ -4338,7 +4390,14 @@ async def handle_input_text_action(if secret_failure is not None:return [secret_failure]else:- await skyvern_element.input_sequentially(text=text)+ contenteditable = await skyvern_element.get_attr("contenteditable", mode="static")+ if contenteditable is not None and str(contenteditable).lower() != "false":+ # A contenteditable rich-text editor that auto-linkifies URLs corrupts a value entered+ # across the input_sequentially fill(prefix)+type(tail) seam, so fill it in one event (SKY-13014).+ await skyvern_element.refresh_locator_if_stale()+ await skyvern_element.input_fill(text)+ else:+ await skyvern_element.input_sequentially(text=text)if log_tel_fallback_readback:await _log_tel_fallback_fill_digit_counts(skyvern_element=skyvern_element,@@ -4947,7 +5006,9 @@ async def handle_select_option_action(await incremental_scraped.start_listen_dom_increment(await skyvern_element.get_element_handler())await skyvern_element.scroll_into_view()- await skyvern_element.click(page=page, dom=dom, timeout=timeout)+ await skyvern_element.click(+ page=page, dom=dom, timeout=timeout, engine_selection=resolve_engine_selection_for_task(task)+ )# The click opens the widget: mark it open now (not only on the incremental path below) so the# finally cleanup dismisses it on every exit — including an emerging-path optional miss that# returns ActionAbort before reaching the incremental branch.@@ -5879,6 +5940,10 @@ async def chain_click(Clicks on an element identified by the css and its parent if failed.:param css: css of the element to click"""+ # Pin the run's selected engine before the first dispatch so every+ # post-dispatch classification below uses one stable authority — a later+ # browser-state removal/replacement must not drift it.+ engine_selection = resolve_engine_selection_for_task(task)# Tracks the return value so the finally block can inspect click success.action_results: list[ActionResult] = []try:@@ -5897,7 +5962,7 @@ async def chain_click(return action_resultsexcept Exception as e:- if is_post_dispatch_click_timeout(e):+ if is_post_dispatch_click_timeout(e, engine_selection):LOG.info("Chain click: physical click dispatched; navigation-wait timed out — skipping fallback",action=action,@@ -5921,6 +5986,14 @@ async def chain_click(action_results.append(ActionSuccess())return action_resultsexcept Exception as e:+ if is_post_dispatch_click_timeout(e, engine_selection):+ LOG.info(+ "Chain click: for-label fallback dispatched; navigation-wait timed out — skipping fallback",+ action=action,+ locator=locator,+ )+ action_results.append(ActionSuccess())+ return action_resultsaction_results.append(ActionFailure(FailToClick(action.element_id, anchor="for", msg=str(e))))try:@@ -5939,6 +6012,14 @@ async def chain_click(action_results.append(ActionSuccess())return action_resultsexcept Exception as e:+ if is_post_dispatch_click_timeout(e, engine_selection):+ LOG.info(+ "Chain click: label-children fallback dispatched; navigation-wait timed out — skipping fallback",+ action=action,+ locator=locator,+ )+ action_results.append(ActionSuccess())+ return action_resultsaction_results.append(ActionFailure(FailToClick(action.element_id, anchor="direct_children", msg=str(e))))@@ -5957,6 +6038,14 @@ async def chain_click(action_results.append(ActionSuccess())return action_resultsexcept Exception as e:+ if is_post_dispatch_click_timeout(e, engine_selection):+ LOG.info(+ "Chain click: attr-id label fallback dispatched; navigation-wait timed out — skipping fallback",+ action=action,+ locator=locator,+ )+ action_results.append(ActionSuccess())+ return action_resultsaction_results.append(ActionFailure(FailToClick(action.element_id, anchor="attr_id", msg=str(e))))try:@@ -5974,6 +6063,14 @@ async def chain_click(action_results.append(ActionSuccess())return action_resultsexcept Exception as e:+ if is_post_dispatch_click_timeout(e, engine_selection):+ LOG.info(+ "Chain click: direct-parent label fallback dispatched; navigation-wait timed out — skipping fallback",+ action=action,+ locator=locator,+ )+ action_results.append(ActionSuccess())+ return action_resultsaction_results.append(ActionFailure(FailToClick(action.element_id, anchor="direct_parent", msg=str(e))))if not await skyvern_element.is_visible():@@ -6148,6 +6245,14 @@ async def chain_click(action_results.append(ActionSuccess())return action_resultsexcept Exception as e:+ if is_post_dispatch_click_timeout(e, engine_selection):+ LOG.info(+ "Chain click: blocking-element fallback dispatched; navigation-wait timed out — skipping fallback",+ action=action,+ locator=locator,+ )+ action_results.append(ActionSuccess())+ return action_resultsaction_results.append(ActionFailure(FailToClick(action.element_id, anchor="blocking_element", msg=str(e))))# Only attempt JS click when the caller provided an observer to verify@@ -6572,7 +6677,7 @@ async def choose_auto_completion_dropdown(static_element=incremental_scraped.id_to_element_dict.get(element_id, {}),)await selected_element.scroll_into_view()- await selected_element.click(page=page)+ await selected_element.click(page=page, engine_selection=resolve_engine_selection_for_task(task))clear_input = Falsereturn result@@ -7857,7 +7962,7 @@ async def _select_deterministic_custom_option(click_attempted = Trueif on_click_attempted is not None:on_click_attempted()- await selected_element.click(page=page)+ await selected_element.click(page=page, engine_selection=resolve_engine_selection_for_task(task))verified = await _verify_custom_select_option_with_settle(matched_element=selected_element,readback_scope_element=readback_scope_element,@@ -7892,7 +7997,9 @@ async def _select_deterministic_custom_option(if anchor_is_combobox_input:# Text-input comboboxes can be safely reset, so an unconfirmed read-back routes to the LLM# mini-agent (which clears/reopens the field) instead of hard-failing the whole action.- reset_verified = await _reset_custom_select_combobox_input(readback_scope_element, page)+ reset_verified = await _reset_custom_select_combobox_input(+ readback_scope_element, page, engine_selection=resolve_engine_selection_for_task(task)+ )if reset_verified:LOG.info("Deterministic custom-select read-back inconclusive on combobox input; routing to LLM fallback",@@ -7931,13 +8038,17 @@ async def _select_deterministic_custom_option(return _terminal_custom_select_failure(target_value=target_value, matched_label=matched_label)-async def _reset_custom_select_combobox_input(element: SkyvernElement | None, page: Page) -> bool:+async def _reset_custom_select_combobox_input(+ element: SkyvernElement | None,+ page: Page,+ engine_selection: BrowserEngineSelection | None = None,+) -> bool:if element is None:return Falsetry:locator = element.get_locator()await locator.fill("")- await element.click(page=page)+ await element.click(page=page, engine_selection=engine_selection)return await get_input_value(element.get_tag_name(), locator) == ""except Exception:LOG.info(@@ -8179,7 +8290,7 @@ async def select_from_emerging_elements(return ActionFailure(exception=InteractWithDropdownContainer(element_id=element_id))await selected_element.scroll_into_view()- await selected_element.click(page=page)+ await selected_element.click(page=page, engine_selection=resolve_engine_selection_for_task(task))return ActionSuccess()@@ -8398,7 +8509,9 @@ async def select_from_dropdown(return single_select_resultawait selected_element.scroll_into_view()- await selected_element.click(page=page, timeout=timeout)+ await selected_element.click(+ page=page, timeout=timeout, engine_selection=resolve_engine_selection_for_task(task)+ )single_select_result.action_result = ActionSuccess()return single_select_resultexcept (MissingElement, MissingElementDict, MissingElementInCSSMap, MultipleElementsFound):diff --git a/skyvern/webeye/utils/dom.py b/skyvern/webeye/utils/dom.pyindex f78768204..4b64657ea 100644--- a/skyvern/webeye/utils/dom.py+++ b/skyvern/webeye/utils/dom.py@@ -750,7 +750,7 @@ class SkyvernElement:return None- def find_deepest_interactable_descendant_in_single_chain(self) -> str | None:+ def find_deepest_interactable_descendant_in_single_chain(self, *, include_disabled: bool = False) -> str | None:children = self.__static_element.get("children")if not isinstance(children, list):return None@@ -775,7 +775,8 @@ class SkyvernElement:continueattrs = item.get("attributes")# Static children expose attrs only; CSS style-disabled is caught by the later dynamic check.- if isinstance(attrs, dict) and self._disabled_attrs_indicate_disabled(attrs):+ # include_disabled keeps a statically-disabled candidate for callers that wait_until_enabled it.+ if not include_disabled and isinstance(attrs, dict) and self._disabled_attrs_indicate_disabled(attrs):grandchildren = item.get("children")if isinstance(grandchildren, list):_walk(grandchildren, child_path)@@ -1208,6 +1209,7 @@ class SkyvernElement:dom: DomUtil | None = None,incremental_page: IncrementalScrapePage | None = None,timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS,+ engine_selection: BrowserEngineSelection | None = None,) -> None:if not await self.wait_until_enabled(timeout=timeout):raise InteractWithDisabledElement(element_id=self.get_id())@@ -1222,7 +1224,7 @@ class SkyvernElement:returnexcept Exception as exc:LOG.info("Failed to click by playwright", exc_info=True, element_id=self.get_id())- if is_post_dispatch_click_timeout(exc):+ if is_post_dispatch_click_timeout(exc, engine_selection):LOG.info("Click side effect detected via navigation-wait timeout — skipping fallback chain",element_id=self.get_id(),@@ -1238,7 +1240,13 @@ class SkyvernElement:LOG.debug("Find the blocking element", element_id=blocking_element.get_id())await blocking_element.get_locator().click(timeout=timeout)return- except Exception:+ except Exception as exc:+ if is_post_dispatch_click_timeout(exc, engine_selection):+ LOG.info(+ "Blocking-element click side effect detected via navigation-wait timeout — skipping fallback chain",+ element_id=self.get_id(),+ )+ returnLOG.info("Failed to click on the blocking element", exc_info=True, element_id=self.get_id())try:diff --git a/tests/unit/test_chain_click_blocked_anchor_navigation.py b/tests/unit/test_chain_click_blocked_anchor_navigation.pyindex 1de3cf0b0..1c57724ad 100644--- a/tests/unit/test_chain_click_blocked_anchor_navigation.py+++ b/tests/unit/test_chain_click_blocked_anchor_navigation.py@@ -12,6 +12,7 @@ from __future__ import annotationsfrom unittest.mock import AsyncMock, MagicMockimport pytest+from playwright.async_api import TimeoutError as PlaywrightTimeoutErrorfrom skyvern.config import settingsfrom skyvern.webeye.utils import dom as dom_module@@ -538,6 +539,434 @@ def test_dom_module_exports_try_navigate_via_href() -> None:assert hasattr(dom_module.SkyvernElement, "try_navigate_via_href")+class _SelectedEngineTimeout(Exception):+ pass+++def _selected_engine() -> MagicMock:+ selection = MagicMock()+ selection.is_engine_timeout_error.side_effect = lambda exc: isinstance(exc, _SelectedEngineTimeout)+ return selection+++class TestChainClickEngineAwarePostDispatch:+ """``chain_click`` must classify a post-dispatch navigation-wait timeout+ against the logical run's selected browser engine — resolved through+ ``resolve_engine_selection_for_task`` — so an alternate engine's native+ timeout short-circuits the fallback exactly like stock Playwright does."""++ _NAV_MSG = (+ "click: Timeout 10000ms exceeded.\nCall log:\n"+ " - performing click action\n - click action done\n"+ " - waiting for scheduled navigations to finish\n"+ )++ @staticmethod+ def _make_element() -> SkyvernElement:+ elem = object.__new__(SkyvernElement)+ elem._SkyvernElement__static_element = {"id": "AAA3", "tagName": "button"} # type: ignore[attr-defined]+ elem.get_tag_name = MagicMock(return_value="button") # type: ignore[method-assign]+ elem.get_id = MagicMock(return_value="AAA3") # type: ignore[method-assign]+ elem.get_element_handler = AsyncMock(return_value=MagicMock()) # type: ignore[method-assign]+ elem.locator = MagicMock()+ elem.navigate_to_a_href = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_bound_label_by_attr_id = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_bound_label_by_direct_parent = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.is_visible = AsyncMock(return_value=True) # type: ignore[method-assign]+ elem.find_blocking_element = AsyncMock(return_value=(None, False)) # type: ignore[method-assign]+ elem.is_checkbox = AsyncMock(return_value=False) # type: ignore[method-assign]+ elem.is_checked = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.coordinate_click = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.click_in_javascript = AsyncMock(return_value=None) # type: ignore[method-assign]+ return elem++ async def _run(+ self,+ monkeypatch: pytest.MonkeyPatch,+ *,+ first_click_exc: Exception,+ engine_selection: MagicMock | None,+ ) -> tuple[list, SkyvernElement]:+ from skyvern.webeye.actions import handler as handler_module+ from skyvern.webeye.actions.actions import ClickAction++ monkeypatch.setattr(+ handler_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=first_click_exc),+ )+ monkeypatch.setattr(handler_module.skyvern_context, "current", MagicMock(return_value=None))+ monkeypatch.setattr(+ handler_module,+ "resolve_engine_selection_for_task",+ MagicMock(return_value=engine_selection),+ )++ elem = self._make_element()+ page = MagicMock()+ page.url = "https://portal.example.com/dashboard"+ page.on = MagicMock()+ task = MagicMock()+ task.organization_id = "org_test"+ action = ClickAction(element_id="AAA3")++ results = await handler_module.chain_click(+ task=task,+ scraped_page=MagicMock(),+ page=page,+ action=action,+ skyvern_element=elem,+ )+ return results, elem++ @pytest.mark.asyncio+ async def test_selected_engine_post_dispatch_timeout_short_circuits_as_success(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ results, elem = await self._run(+ monkeypatch,+ first_click_exc=_SelectedEngineTimeout(self._NAV_MSG),+ engine_selection=_selected_engine(),+ )++ assert results and isinstance(results[-1], ActionSuccess)+ elem.coordinate_click.assert_not_called()+ elem.click_in_javascript.assert_not_called()++ @pytest.mark.asyncio+ async def test_foreign_engine_timeout_is_not_classified_and_falls_through(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ # A stock Playwright timeout is foreign to the selected engine: it must+ # not be treated as a completed side effect, so the coordinate fallback+ # still runs.+ from playwright.async_api import TimeoutError as PlaywrightTimeoutError++ _, elem = await self._run(+ monkeypatch,+ first_click_exc=PlaywrightTimeoutError(self._NAV_MSG),+ engine_selection=_selected_engine(),+ )++ elem.coordinate_click.assert_awaited_once()++ @pytest.mark.asyncio+ async def test_none_engine_selection_matches_stock_playwright_short_circuit(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from playwright.async_api import TimeoutError as PlaywrightTimeoutError++ from skyvern.webeye.actions.responses import ActionSuccess++ results, elem = await self._run(+ monkeypatch,+ first_click_exc=PlaywrightTimeoutError(self._NAV_MSG),+ engine_selection=None,+ )++ assert results and isinstance(results[-1], ActionSuccess)+ elem.coordinate_click.assert_not_called()+++_LADDER_NAV_MSG = (+ "click: Timeout 10000ms exceeded.\nCall log:\n"+ " - performing click action\n - click action done\n"+ " - waiting for scheduled navigations to finish\n"+)+++def _bound_click_element(click_mock: AsyncMock) -> MagicMock:+ """A ``SkyvernElement``-like bound element whose ``get_locator().click`` is+ ``click_mock`` (used by the for-label / label-children fallbacks)."""+ bound = MagicMock()+ loc = MagicMock()+ loc.click = click_mock+ loc.dblclick = AsyncMock(return_value=None)+ bound.get_locator = MagicMock(return_value=loc)+ return bound+++def _bound_click_locator(click_mock: AsyncMock) -> MagicMock:+ """A raw Locator whose ``click`` is ``click_mock`` (used by the+ bound-label-by-attr-id / by-direct-parent fallbacks)."""+ loc = MagicMock()+ loc.click = click_mock+ loc.dblclick = AsyncMock(return_value=None)+ return loc+++def _blocking_click_element(click_mock: AsyncMock) -> MagicMock:+ blocker = MagicMock()+ loc = MagicMock()+ loc.click = click_mock+ blocker.get_locator = MagicMock(return_value=loc)+ blocker.get_id = MagicMock(return_value="BLK")+ blocker.is_parent_of = AsyncMock(return_value=True)+ blocker.is_sibling_of = AsyncMock(return_value=False)+ blocker.is_safe_for_checkbox_direct_click = AsyncMock(return_value=True)+ return blocker+++def _make_ladder_element(*, tag: str = "button", **stubs: object) -> SkyvernElement:+ elem = object.__new__(SkyvernElement)+ elem._SkyvernElement__static_element = {"id": "AAA3", "tagName": tag} # type: ignore[attr-defined]+ elem.get_tag_name = MagicMock(return_value=tag) # type: ignore[method-assign]+ elem.get_id = MagicMock(return_value="AAA3") # type: ignore[method-assign]+ elem.get_element_handler = AsyncMock(return_value=MagicMock()) # type: ignore[method-assign]+ elem.locator = MagicMock()+ elem.navigate_to_a_href = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_label_for = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_element_in_label_children = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_bound_label_by_attr_id = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.find_bound_label_by_direct_parent = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.is_visible = AsyncMock(return_value=True) # type: ignore[method-assign]+ elem.find_blocking_element = AsyncMock(return_value=(None, False)) # type: ignore[method-assign]+ elem.is_checkbox = AsyncMock(return_value=False) # type: ignore[method-assign]+ elem.is_checked = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.coordinate_click = AsyncMock(return_value=None) # type: ignore[method-assign]+ elem.click_in_javascript = AsyncMock(return_value=None) # type: ignore[method-assign]+ for name, value in stubs.items():+ setattr(elem, name, value)+ return elem+++async def _run_ladder(+ monkeypatch: pytest.MonkeyPatch,+ elem: SkyvernElement,+ engine_selection: MagicMock | None,+) -> list:+ from skyvern.webeye.actions import handler as handler_module+ from skyvern.webeye.actions.actions import ClickAction++ monkeypatch.setattr(+ handler_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=RuntimeError("primary click failed")),+ )+ monkeypatch.setattr(handler_module.skyvern_context, "current", MagicMock(return_value=None))+ monkeypatch.setattr(+ handler_module,+ "resolve_engine_selection_for_task",+ MagicMock(return_value=engine_selection),+ )++ page = MagicMock()+ page.url = "https://portal.example.com/dashboard"+ page.on = MagicMock()+ task = MagicMock()+ task.organization_id = "org_test"+ action = ClickAction(element_id="AAA3")++ return await handler_module.chain_click(+ task=task,+ scraped_page=MagicMock(),+ page=page,+ action=action,+ skyvern_element=elem,+ )+++class TestChainClickFallbackPostDispatchGuard:+ """Each side-effecting fallback locator click in ``chain_click`` can itself+ dispatch then time out on the post-click navigation wait. When classified+ against the run's selected engine (or stock Playwright for ``None``) that+ means the side effect already fired, so the remaining ladder must not+ re-click. A foreign-engine timeout stays a plain failure and the existing+ ladder continues."""++ # --- for-label fallback (label element -> find_label_for) ---------------++ @pytest.mark.asyncio+ async def test_for_label_selected_timeout_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ bound = _bound_click_element(AsyncMock(side_effect=_SelectedEngineTimeout(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_label_for=AsyncMock(return_value=bound))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionSuccess)+ elem.find_element_in_label_children.assert_not_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_not_awaited() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_for_label_foreign_timeout_continues_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ bound = _bound_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_label_for=AsyncMock(return_value=bound))++ await _run_ladder(monkeypatch, elem, _selected_engine())++ elem.find_element_in_label_children.assert_awaited_once() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_for_label_none_engine_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ bound = _bound_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_label_for=AsyncMock(return_value=bound))++ results = await _run_ladder(monkeypatch, elem, None)++ assert results and isinstance(results[-1], ActionSuccess)+ elem.find_element_in_label_children.assert_not_awaited() # type: ignore[attr-defined]++ # --- label-children fallback (label element -> find_element_in_label_children)++ @pytest.mark.asyncio+ async def test_label_children_selected_timeout_skips_remaining_fallback(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ bound = _bound_click_element(AsyncMock(side_effect=_SelectedEngineTimeout(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_element_in_label_children=AsyncMock(return_value=bound))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionSuccess)+ elem.is_visible.assert_not_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_not_awaited() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_label_children_foreign_timeout_continues_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ bound = _bound_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_element_in_label_children=AsyncMock(return_value=bound))++ await _run_ladder(monkeypatch, elem, _selected_engine())++ elem.is_visible.assert_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_awaited_once() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_label_children_none_engine_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ bound = _bound_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="label", find_element_in_label_children=AsyncMock(return_value=bound))++ results = await _run_ladder(monkeypatch, elem, None)++ assert results and isinstance(results[-1], ActionSuccess)+ elem.is_visible.assert_not_awaited() # type: ignore[attr-defined]++ # --- bound-label-by-attr-id fallback (non-label element) ----------------++ @pytest.mark.asyncio+ async def test_attr_id_selected_timeout_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ locator = _bound_click_locator(AsyncMock(side_effect=_SelectedEngineTimeout(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_attr_id=AsyncMock(return_value=locator))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionSuccess)+ elem.find_bound_label_by_direct_parent.assert_not_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_not_awaited() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_attr_id_foreign_timeout_continues_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ locator = _bound_click_locator(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_attr_id=AsyncMock(return_value=locator))++ await _run_ladder(monkeypatch, elem, _selected_engine())++ elem.find_bound_label_by_direct_parent.assert_awaited_once() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_attr_id_none_engine_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ locator = _bound_click_locator(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_attr_id=AsyncMock(return_value=locator))++ results = await _run_ladder(monkeypatch, elem, None)++ assert results and isinstance(results[-1], ActionSuccess)+ elem.find_bound_label_by_direct_parent.assert_not_awaited() # type: ignore[attr-defined]++ # --- bound-label-by-direct-parent fallback (non-label element) ----------++ @pytest.mark.asyncio+ async def test_direct_parent_selected_timeout_skips_remaining_fallback(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ locator = _bound_click_locator(AsyncMock(side_effect=_SelectedEngineTimeout(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_direct_parent=AsyncMock(return_value=locator))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionSuccess)+ elem.is_visible.assert_not_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_not_awaited() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_direct_parent_foreign_timeout_continues_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ locator = _bound_click_locator(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_direct_parent=AsyncMock(return_value=locator))++ await _run_ladder(monkeypatch, elem, _selected_engine())++ elem.is_visible.assert_awaited() # type: ignore[attr-defined]+ elem.coordinate_click.assert_awaited_once() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_direct_parent_none_engine_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ locator = _bound_click_locator(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_bound_label_by_direct_parent=AsyncMock(return_value=locator))++ results = await _run_ladder(monkeypatch, elem, None)++ assert results and isinstance(results[-1], ActionSuccess)+ elem.is_visible.assert_not_awaited() # type: ignore[attr-defined]++ # --- blocking-element (parent/sibling) fallback -------------------------++ @pytest.mark.asyncio+ async def test_blocking_element_selected_timeout_skips_remaining_fallback(+ self, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ blocker = _blocking_click_element(AsyncMock(side_effect=_SelectedEngineTimeout(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_blocking_element=AsyncMock(return_value=(blocker, True)))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionSuccess)+ elem.click_in_javascript.assert_not_awaited() # type: ignore[attr-defined]++ @pytest.mark.asyncio+ async def test_blocking_element_foreign_timeout_stays_failure(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionFailure++ blocker = _blocking_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_blocking_element=AsyncMock(return_value=(blocker, True)))++ results = await _run_ladder(monkeypatch, elem, _selected_engine())++ assert results and isinstance(results[-1], ActionFailure)+ assert "blocking_element" in results[-1].exception_message++ @pytest.mark.asyncio+ async def test_blocking_element_none_engine_skips_remaining_fallback(self, monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.webeye.actions.responses import ActionSuccess++ blocker = _blocking_click_element(AsyncMock(side_effect=PlaywrightTimeoutError(_LADDER_NAV_MSG)))+ elem = _make_ladder_element(tag="button", find_blocking_element=AsyncMock(return_value=(blocker, True)))++ results = await _run_ladder(monkeypatch, elem, None)++ assert results and isinstance(results[-1], ActionSuccess)+ elem.click_in_javascript.assert_not_awaited() # type: ignore[attr-defined]++class TestChainClickCheckboxCoordinateVerification:"""Slice 2 wired through the real ``chain_click`` production branch: acheckbox that reaches the coordinate fallback is state-verified, anddiff --git a/tests/unit/test_disabled_control_readiness.py b/tests/unit/test_disabled_control_readiness.pyindex 8966f5250..e22166402 100644--- a/tests/unit/test_disabled_control_readiness.py+++ b/tests/unit/test_disabled_control_readiness.py@@ -115,6 +115,7 @@ async def test_input_handler_classifies_control_that_stays_disabled() -> None:element.get_tag_name.return_value = "input"element.get_frame.return_value = MagicMock()element.get_locator.return_value = MagicMock()+ element.supports_text_input = AsyncMock(return_value=True)dom = MagicMock()dom.get_skyvern_element_by_id = AsyncMock(return_value=element)frame = MagicMock()diff --git a/tests/unit/test_element_click_navigation_timeout_skips_fallback.py b/tests/unit/test_element_click_navigation_timeout_skips_fallback.pyindex 98e4693e5..e9ace0edf 100644--- a/tests/unit/test_element_click_navigation_timeout_skips_fallback.py+++ b/tests/unit/test_element_click_navigation_timeout_skips_fallback.py@@ -158,3 +158,140 @@ async def test_click_happy_path_returns_without_fallback(monkeypatch: pytest.Monelem.coordinate_click.assert_not_called()elem.click_in_javascript.assert_not_called()+++async def test_click_selected_engine_navigation_timeout_skips_fallback_chain(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The selected engine raises its own (non-Playwright) timeout class after+ dispatching the click. Classified against THIS run's engine, it is still a+ post-dispatch navigation-wait timeout, so the fallback chain must not+ re-click and duplicate the side effect."""+ elem = _make_element()+ monkeypatch.setattr(+ dom_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=SelectedEngineTimeout(_NAVIGATION_TIMEOUT_MSG)),+ )++ await elem.click(page=MagicMock(), dom=None, timeout=1000.0, engine_selection=_selected_engine())++ elem.coordinate_click.assert_not_called()+ elem.click_in_javascript.assert_not_called()+ elem.scroll_into_view.assert_not_called()+++async def test_click_foreign_engine_navigation_timeout_runs_full_fallback_chain(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A stock Playwright timeout is foreign to the selected engine: even though+ the message references scheduled navigation, it must not be classified as a+ post-dispatch side effect, so the existing fallback chain still runs."""+ elem = _make_element()+ monkeypatch.setattr(+ dom_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=PlaywrightTimeoutError(_NAVIGATION_TIMEOUT_MSG)),+ )+ elem.coordinate_click = AsyncMock(side_effect=RuntimeError("no bbox")) # type: ignore[method-assign]++ await elem.click(page=MagicMock(), dom=None, timeout=1000.0, engine_selection=_selected_engine())++ elem.coordinate_click.assert_awaited_once()+ elem.click_in_javascript.assert_awaited_once()+++async def test_click_explicit_none_engine_selection_matches_stock_playwright(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Passing ``engine_selection=None`` keeps the stock Playwright identity: a+ Playwright navigation-wait timeout is treated as a completed side effect."""+ elem = _make_element()+ monkeypatch.setattr(+ dom_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=PlaywrightTimeoutError(_NAVIGATION_TIMEOUT_MSG)),+ )++ await elem.click(page=MagicMock(), dom=None, timeout=1000.0, engine_selection=None)++ elem.coordinate_click.assert_not_called()+ elem.click_in_javascript.assert_not_called()+++class TestBlockingElementFallbackPostDispatch:+ """The blocking-element fallback inside ``SkyvernElement.click`` can itself+ physically dispatch a click that only times out on the post-click navigation+ wait. That means the side effect already fired, so the coordinate/JS+ fallbacks must not run and re-dispatch it — classified against THIS run's+ selected engine."""++ @staticmethod+ def _element_with_blocking(blocking_click: AsyncMock) -> tuple[SkyvernElement, MagicMock]:+ elem = _make_element()+ blocking = MagicMock()+ blocking.get_id = MagicMock(return_value="BLK")+ blocking_locator = MagicMock()+ blocking_locator.click = blocking_click+ blocking.get_locator = MagicMock(return_value=blocking_locator)+ elem.find_blocking_element = AsyncMock(return_value=(blocking, False)) # type: ignore[method-assign]+ return elem, blocking_locator++ @pytest.fixture(autouse=True)+ def _primary_click_fails_non_post_dispatch(self, monkeypatch: pytest.MonkeyPatch) -> None:+ # A non-timeout first-click failure routes execution into the dom-aware+ # blocking-element fallback that these tests exercise.+ monkeypatch.setattr(+ dom_module.EventStrategyFactory,+ "click_element",+ AsyncMock(side_effect=RuntimeError("primary click failed")),+ )++ @pytest.mark.asyncio+ async def test_selected_native_navigation_timeout_skips_remaining_fallback(self) -> None:+ elem, blocking_locator = self._element_with_blocking(+ AsyncMock(side_effect=SelectedEngineTimeout(_NAVIGATION_TIMEOUT_MSG))+ )++ await elem.click(page=MagicMock(), dom=MagicMock(), timeout=1000.0, engine_selection=_selected_engine())++ blocking_locator.click.assert_awaited_once()+ elem.coordinate_click.assert_not_called()+ elem.click_in_javascript.assert_not_called()++ @pytest.mark.asyncio+ async def test_foreign_navigation_timeout_continues_fallback(self) -> None:+ elem, blocking_locator = self._element_with_blocking(+ AsyncMock(side_effect=PlaywrightTimeoutError(_NAVIGATION_TIMEOUT_MSG))+ )++ await elem.click(page=MagicMock(), dom=MagicMock(), timeout=1000.0, engine_selection=_selected_engine())++ blocking_locator.click.assert_awaited_once()+ elem.coordinate_click.assert_awaited_once()++ @pytest.mark.asyncio+ async def test_none_engine_selection_skips_remaining_fallback(self) -> None:+ elem, blocking_locator = self._element_with_blocking(+ AsyncMock(side_effect=PlaywrightTimeoutError(_NAVIGATION_TIMEOUT_MSG))+ )++ await elem.click(page=MagicMock(), dom=MagicMock(), timeout=1000.0, engine_selection=None)++ blocking_locator.click.assert_awaited_once()+ elem.coordinate_click.assert_not_called()+ elem.click_in_javascript.assert_not_called()++ @pytest.mark.asyncio+ async def test_non_timeout_blocking_error_continues_fallback(self) -> None:+ elem, blocking_locator = self._element_with_blocking(+ AsyncMock(side_effect=RuntimeError("blocker click failed"))+ )++ await elem.click(page=MagicMock(), dom=MagicMock(), timeout=1000.0, engine_selection=None)++ blocking_locator.click.assert_awaited_once()+ elem.coordinate_click.assert_awaited_once()diff --git a/tests/unit/test_input_text_tel_card_routing.py b/tests/unit/test_input_text_tel_card_routing.pyindex 085e333af..de0bb3c42 100644--- a/tests/unit/test_input_text_tel_card_routing.py+++ b/tests/unit/test_input_text_tel_card_routing.py@@ -44,6 +44,7 @@ def _mock_input(attrs: dict[str, str | None]) -> MagicMock:el.input_sequentially = AsyncMock()el.input_clear = AsyncMock()el.input_fill = AsyncMock()+ el.refresh_locator_if_stale = AsyncMock()el.press_key = AsyncMock()return el@@ -295,8 +296,9 @@ async def test_single_character_secret_skips_readback() -> None:@pytest.mark.asyncioasync def test_secret_in_non_input_element_skips_readback() -> None:- # A contenteditable/div is not a native input (its read-back is trimmed/normalized), so the read-back- # is skipped; it keeps the plain sequential fill and its pre-existing behavior.+ # A non-native editable sink (a plain <div> with no contenteditable attribute) trims/normalizes its+ # read-back, so the exact-value read-back is skipped. It is not an explicit contenteditable, so it keeps+ # the per-key sequential fill; only an explicit contenteditable takes the atomic path.el = _mock_input({"type": None, "autocomplete": None, "name": "note"})el.get_tag_name.return_value = "div"@@ -306,6 +308,45 @@ async def test_secret_in_non_input_element_skips_readback() -> None:assert len(results) == 1 and isinstance(results[0], ActionSuccess)el.input_sequentially.assert_awaited_once_with(text="mysecretvalue")+ el.input_fill.assert_not_awaited()+ secret_readback.assert_not_awaited()+++async def test_explicit_contenteditable_url_uses_atomic_fill_not_sequential_seam() -> None:+ # SKY-13014: a Quill-style rich-text editor carries contenteditable="true". Filling it with the+ # input_sequentially fill(prefix)+type(tail) split lets a URL auto-linkifier wrap the prefix before the+ # tail arrives, corrupting the link. An explicit contenteditable must fill atomically via input_fill and+ # keep the stale-locator refresh locally (input_fill alone skips it); input_sequentially must not run.+ el = _mock_input({"type": None, "autocomplete": None, "name": "key-take-aways", "contenteditable": "true"})+ el.get_tag_name.return_value = "div"+ url_value = "https://example.com/shared/call/CUPRZqEEAWnXLTaMSGhrnR5UW5RZVthv8b6MZTiDGtmY"++ results, _, _, _, _, secret_readback = await _run_input_text(el, url_value, tag_name="div")++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_fill.assert_awaited_once_with(url_value)+ el.refresh_locator_if_stale.assert_awaited_once()+ el.input_sequentially.assert_not_awaited()+ secret_readback.assert_not_awaited()+++async def test_non_contenteditable_custom_sink_url_keeps_sequential_fill() -> None:+ # Scope regression (SKY-13014): the atomic path is reserved for an explicit contenteditable. A non-native+ # custom sink that is editable but has no contenteditable attribute (here a role=textbox div) must keep+ # the per-key sequential fill even for a URL value -- it must not be widened onto the atomic branch, and+ # the contenteditable-only stale-locator refresh must not run for it.+ el = _mock_input({"type": None, "autocomplete": None, "name": "widget", "role": "textbox"})+ el.get_tag_name.return_value = "div"+ url_value = "https://example.com/shared/call/CUPRZqEEAWnXLTaMSGhrnR5UW5RZVthv8b6MZTiDGtmY"++ results, _, _, _, _, secret_readback = await _run_input_text(el, url_value, tag_name="div")++ assert len(results) == 1 and isinstance(results[0], ActionSuccess)+ el.input_sequentially.assert_awaited_once_with(text=url_value)+ el.input_fill.assert_not_awaited()+ el.refresh_locator_if_stale.assert_not_awaited()secret_readback.assert_not_awaited()diff --git a/tests/unit/test_input_text_wrapper_retarget.py b/tests/unit/test_input_text_wrapper_retarget.pynew file mode 100644index 000000000..4c5babaf5--- /dev/null+++ b/tests/unit/test_input_text_wrapper_retarget.py@@ -0,0 +1,479 @@+"""input_text wrapper -> nested-input retarget (cross-origin secure card-entry fields).++The visible card-field target is a wrapper <div>/<iframe> (interactable: false); the usable+<input> lives one frame deeper (a distinct frame_index, interactable: true). Without a retarget,+input_text rejects the wrapper and relies on the LLM to descend on retry -- which it does only+inconsistently. These tests pin the deterministic, fail-closed retarget and its production wiring.+"""++from __future__ import annotations++from datetime import UTC, datetime+from unittest.mock import AsyncMock, MagicMock, patch++import pytest++from skyvern.exceptions import InputToInvisibleElement, InteractWithDisabledElement, InvalidElementForTextInput+from skyvern.forge.sdk.models import StepStatus+from skyvern.webeye.actions.actions import InputTextAction+from skyvern.webeye.actions.handler import _retarget_wrapper_for_input_text, handle_input_text_action+from skyvern.webeye.actions.responses import ActionFailure, ActionSuccess+from skyvern.webeye.utils.dom import SkyvernElement+from tests.unit.helpers import make_organization, make_step, make_task++_NOW = datetime.now(UTC)+_ORG = make_organization(_NOW)+_TASK = make_task(_NOW, _ORG, navigation_payload={}, navigation_goal="enter the card number")+_STEP = make_step(_NOW, _TASK, step_id="stp-wrap-retarget-1", status=StepStatus.created, order=0, output=None)++_CARD = "4111111111111111"+++def _mock_wrapper(*, deepest_descendant: str | None) -> MagicMock:+ el = MagicMock()+ el.get_id.return_value = "IFRM"+ el.get_tag_name.return_value = "iframe"+ el.get_frame.return_value = MagicMock()+ el.supports_text_input = AsyncMock(return_value=False)+ el.has_hidden_attr = AsyncMock(return_value=False)+ el.find_deepest_interactable_descendant_in_single_chain = MagicMock(return_value=deepest_descendant)+ # Reached only if a reject path runs on the wrapper itself (fail-closed cases).+ el.is_disabled = AsyncMock(return_value=False)+ el.get_selectable = AsyncMock(return_value=False)+ el.is_readonly = AsyncMock(return_value=False)+ el.get_attr = AsyncMock(return_value=None)+ el.is_spinbtn_input = AsyncMock(return_value=False)+ el.is_editable = AsyncMock(return_value=False)+ el.is_raw_input = AsyncMock(return_value=False)+ el.is_visible = AsyncMock(return_value=True)+ el.find_blocking_element = AsyncMock(return_value=(None, False))+ el.get_element_handler = AsyncMock(return_value=MagicMock())+ el.input_clear = AsyncMock()+ el.input_fill = AsyncMock()+ el.scroll_into_view = AsyncMock()+ locator = MagicMock()+ locator.focus = AsyncMock()+ el.get_locator.return_value = locator+ return el+++def _mock_nested_input(*, element_id: str, supports_text: bool, disabled: bool = False) -> MagicMock:+ el = MagicMock()+ el.get_id.return_value = element_id+ el.get_tag_name.return_value = "input"+ el.get_frame.return_value = MagicMock()+ el.supports_text_input = AsyncMock(return_value=supports_text)+ el.is_disabled = AsyncMock(return_value=disabled)+ el.has_hidden_attr = AsyncMock(return_value=False)+ el.is_visible = AsyncMock(return_value=True)+ locator = MagicMock()+ locator.focus = AsyncMock()+ el.get_locator.return_value = locator+ return el+++async def _run(action: InputTextAction, wrapper: MagicMock, child: MagicMock | None) -> tuple[list, list[str]]:+ elements: dict = {"IFRM": wrapper}+ if child is not None:+ elements["CARD_INPUT"] = child+ dom_instance = MagicMock()+ dom_instance.get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements[eid])+ dom_instance.safe_get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements.get(eid))++ skyvern_frame = MagicMock()+ skyvern_frame.safe_wait_for_animation_end = AsyncMock()++ scraped_page = MagicMock()+ scraped_page.id_to_element_dict = {"IFRM": {"tagName": "iframe"}, "CARD_INPUT": {"tagName": "input"}}++ # Record which element's tag each current-value read hits. Early normalization reads the value once,+ # from the normalized target; a recursive re-run (the design we avoid) would read twice -- the+ # wrapper's iframe first, then the nested input. The nested <input> reads back the card value so a+ # successful retarget short-circuits to success, proving the child drove the pipeline.+ read_tags: list[str] = []++ async def _get_input_value(tag_name: str, locator: object) -> str:+ read_tags.append(tag_name)+ return _CARD if tag_name == "input" else ""++ with (+ patch("skyvern.webeye.actions.handler.DomUtil", return_value=dom_instance),+ patch(+ "skyvern.webeye.actions.handler.SkyvernFrame.create_instance",+ new=AsyncMock(return_value=skyvern_frame),+ ),+ patch("skyvern.webeye.actions.handler.IncrementalScrapePage", return_value=MagicMock()),+ patch("skyvern.webeye.actions.handler.get_input_value", new=AsyncMock(side_effect=_get_input_value)),+ patch(+ "skyvern.webeye.actions.handler.get_actual_value_of_parameter_if_secret_with_task",+ return_value=_CARD,+ ),+ patch("skyvern.webeye.actions.handler._get_input_or_select_context", new=AsyncMock(return_value=None)),+ ):+ results = await handle_input_text_action(+ action=action, page=MagicMock(), scraped_page=scraped_page, task=_TASK, step=_STEP+ )+ return results, read_tags+++async def test_wrapper_retargets_to_nested_input() -> None:+ wrapper = _mock_wrapper(deepest_descendant="CARD_INPUT")+ child = _mock_nested_input(element_id="CARD_INPUT", supports_text=True)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="enter card number")++ # After retargeting to the nested input, its rendered value already equals the target, so the+ # handler short-circuits to success -- proving the wrapper was resolved to the real <input>.+ results, read_tags = await _run(action, wrapper, child)++ assert action.element_id == "CARD_INPUT"+ assert len(results) == 1+ assert isinstance(results[0], ActionSuccess)+ # Exactly one current-value read, against the nested <input> tag: the normalized child drove the+ # pipeline in a single pass, with no recursive handler re-entry (which would read iframe then input).+ assert read_tags == ["input"]+++async def test_ambiguous_descendants_preserve_reject() -> None:+ # Real helper returns None for sibling/decoy inputs (separate branches). No retarget, no mis-fill.+ wrapper = _mock_wrapper(deepest_descendant=None)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="enter card number")++ results, read_tags = await _run(action, wrapper, None)++ assert action.element_id == "IFRM"+ assert len(results) == 1+ assert isinstance(results[0], ActionFailure)+ assert results[0].exception_type == InvalidElementForTextInput.__name__+ # Value read once from the wrapper (iframe) itself: no retarget occurred, single pass to the reject.+ assert read_tags == ["iframe"]+++async def test_nested_candidate_without_text_input_preserves_reject() -> None:+ wrapper = _mock_wrapper(deepest_descendant="CARD_INPUT")+ child = _mock_nested_input(element_id="CARD_INPUT", supports_text=False)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="enter card number")++ results, read_tags = await _run(action, wrapper, child)++ assert action.element_id == "IFRM"+ assert len(results) == 1+ assert isinstance(results[0], ActionFailure)+ assert results[0].exception_type == InvalidElementForTextInput.__name__+ # Nested candidate rejected by the helper's text-input gate: element unchanged, value read once from+ # the wrapper (iframe), single pass to the reject.+ assert read_tags == ["iframe"]+++async def test_hidden_non_text_wrapper_rejects_and_reads_hidden_attr_once() -> None:+ # A genuinely hidden, non-text target is still rejected as invisible; the wrapper's dynamic hidden+ # state read for the retarget gate is cached and reused at the reject block, so has_hidden_attr+ # (two Playwright round-trips) is awaited exactly once instead of twice.+ wrapper = _mock_wrapper(deepest_descendant=None)+ wrapper.has_hidden_attr = AsyncMock(return_value=True)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="enter card number")++ results, _ = await _run(action, wrapper, None)++ assert action.element_id == "IFRM"+ assert len(results) == 1+ assert isinstance(results[0], ActionFailure)+ assert results[0].exception_type == InputToInvisibleElement.__name__+ wrapper.has_hidden_attr.assert_awaited_once()+++async def test_selectable_wrapper_routes_to_select_not_retarget() -> None:+ # A selectable wrapper that happens to expose a unique nested input must still flow through the+ # existing input -> select-option conversion, not be retargeted/typed into the child. Selectable+ # targets are gated out of the retarget entirely, so the descendant helper is never consulted.+ wrapper = _mock_wrapper(deepest_descendant="CARD_INPUT")+ wrapper.get_selectable = AsyncMock(return_value=True)+ child = _mock_nested_input(element_id="CARD_INPUT", supports_text=True)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="choose the saved card")++ elements = {"IFRM": wrapper, "CARD_INPUT": child}+ dom_instance = MagicMock()+ dom_instance.get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements[eid])+ dom_instance.safe_get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements.get(eid))++ scraped_page = MagicMock()+ scraped_page.id_to_element_dict = {"IFRM": {"tagName": "iframe"}, "CARD_INPUT": {"tagName": "input"}}++ select_spy = AsyncMock(return_value=[ActionSuccess()])++ with (+ patch("skyvern.webeye.actions.handler.DomUtil", return_value=dom_instance),+ patch("skyvern.webeye.actions.handler.SkyvernFrame.create_instance", new=AsyncMock(return_value=MagicMock())),+ patch("skyvern.webeye.actions.handler.IncrementalScrapePage", return_value=MagicMock()),+ patch("skyvern.webeye.actions.handler.get_input_value", new=AsyncMock(return_value="")),+ patch("skyvern.webeye.actions.handler.get_actual_value_of_parameter_if_secret_with_task", return_value=_CARD),+ patch("skyvern.webeye.actions.handler.handle_select_option_action", new=select_spy),+ ):+ results = await handle_input_text_action(+ action=action, page=MagicMock(), scraped_page=scraped_page, task=_TASK, step=_STEP+ )++ assert isinstance(results[0], ActionSuccess)+ # Routed to select-option conversion on the ORIGINAL wrapper; the retarget path never ran.+ select_spy.assert_awaited_once()+ assert select_spy.await_args.args[0].element_id == "IFRM"+ assert action.element_id == "IFRM"+ wrapper.find_deepest_interactable_descendant_in_single_chain.assert_not_called()+++async def test_retargeted_disabled_child_waits_then_fails_closed_when_never_enabled() -> None:+ # A retargeted-but-still-disabled nested input must be waited on (wait_until_enabled) and, if it+ # never enables, fail closed on the CHILD with InteractWithDisabledElement -- not reject the+ # wrapper with InvalidElementForTextInput. Proves the child drives the normal pipeline, wait included.+ wrapper = _mock_wrapper(deepest_descendant="CARD_INPUT")+ child = _mock_nested_input(element_id="CARD_INPUT", supports_text=True, disabled=True)+ child.get_selectable = AsyncMock(return_value=False)+ action = InputTextAction(element_id="IFRM", text=_CARD, reasoning="enter card number")++ elements = {"IFRM": wrapper, "CARD_INPUT": child}+ dom_instance = MagicMock()+ dom_instance.get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements[eid])+ dom_instance.safe_get_skyvern_element_by_id = AsyncMock(side_effect=lambda eid: elements.get(eid))++ scraped_page = MagicMock()+ scraped_page.id_to_element_dict = {"IFRM": {"tagName": "iframe"}, "CARD_INPUT": {"tagName": "input"}}++ wait_spy = AsyncMock(return_value=False)++ with (+ patch("skyvern.webeye.actions.handler.DomUtil", return_value=dom_instance),+ patch("skyvern.webeye.actions.handler.SkyvernFrame.create_instance", new=AsyncMock(return_value=MagicMock())),+ patch("skyvern.webeye.actions.handler.IncrementalScrapePage", return_value=MagicMock()),+ patch("skyvern.webeye.actions.handler.get_input_value", new=AsyncMock(return_value="")),+ patch("skyvern.webeye.actions.handler.get_actual_value_of_parameter_if_secret_with_task", return_value=_CARD),+ patch("skyvern.webeye.actions.handler.SkyvernElement.wait_until_enabled", new=wait_spy),+ ):+ results = await handle_input_text_action(+ action=action, page=MagicMock(), scraped_page=scraped_page, task=_TASK, step=_STEP+ )++ # Retargeted to the child, the enabled-wait ran on the child, and it failed closed on the child.+ assert action.element_id == "CARD_INPUT"+ wait_spy.assert_awaited_once()+ assert wait_spy.await_args.args[0] is child+ assert len(results) == 1+ assert isinstance(results[0], ActionFailure)+ assert results[0].exception_type == InteractWithDisabledElement.__name__+++# --- helper-level tests: real single-chain structural logic on the nested-iframe shape ---+++def _static(+ *,+ element_id: str,+ tag_name: str,+ interactable: bool,+ hidden: bool = False,+ disabled: bool = False,+ children: list[dict] | None = None,+) -> dict:+ attrs: dict = {}+ if hidden:+ attrs["aria-hidden"] = "true"+ if disabled:+ attrs["disabled"] = True+ return {+ "id": element_id,+ "tagName": tag_name,+ "interactable": interactable,+ "hoverOnly": False,+ "attributes": attrs,+ "children": children or [],+ }+++def _el(static: dict) -> SkyvernElement:+ return SkyvernElement(MagicMock(), MagicMock(), static)+++def _nested_secure_field_wrapper(*, decoys_interactable: bool) -> SkyvernElement:+ # <div AADN> -> <iframe AADO (interactable:false)> -> <input aAAC (interactable:true)> (+ 3 decoys)+ real = _static(element_id="aAAC", tag_name="input", interactable=True)+ decoys = [+ _static(element_id=did, tag_name="input", interactable=decoys_interactable) for did in ("aAAB", "aAAD", "aAAE")+ ]+ iframe = _static(element_id="AADO", tag_name="iframe", interactable=False, children=[real, *decoys])+ wrapper_div = _static(element_id="AADN", tag_name="div", interactable=False, children=[iframe])+ return _el(wrapper_div)+++def _stub_child(+ static: dict, *, disabled: bool = False, hidden: bool = False, supports_text: bool = True, visible: bool = True+) -> SkyvernElement:+ child = _el(static)+ child.is_disabled = AsyncMock(return_value=disabled) # type: ignore[method-assign]+ child.has_hidden_attr = AsyncMock(return_value=hidden) # type: ignore[method-assign]+ child.supports_text_input = AsyncMock(return_value=supports_text) # type: ignore[method-assign]+ child.is_visible = AsyncMock(return_value=visible) # type: ignore[method-assign]+ return child+++async def test_helper_resolves_single_nested_input_when_decoys_inert() -> None:+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True))+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is child+ assert action.element_id == "aAAC"+ dom.safe_get_skyvern_element_by_id.assert_awaited_once_with("aAAC")+++async def test_helper_bails_when_decoys_interactable() -> None:+ # Interactable decoys are siblings of the real input -> separate branches -> no unambiguous+ # target. Fail-closed: preserve the reject rather than risk typing the card into a decoy.+ parent = _nested_secure_field_wrapper(decoys_interactable=True)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock()+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is None+ assert action.element_id == "AADN"+ dom.safe_get_skyvern_element_by_id.assert_not_called()+++async def test_helper_retargets_child_reporting_disabled() -> None:+ # A transiently-disabled unique nested input must still be retargeted -- the downstream+ # wait_until_enabled then waits on the real input instead of failing closed on the wrapper.+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True), disabled=True)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is child+ assert action.element_id == "aAAC"+++def _nested_secure_field_wrapper_disabled_real(*, decoys_interactable: bool) -> SkyvernElement:+ # Same shape as _nested_secure_field_wrapper, but the real input is disabled at scrape time+ # (provider still enabling it). It must remain the single retarget candidate.+ real = _static(element_id="aAAC", tag_name="input", interactable=True, disabled=True)+ decoys = [+ _static(element_id=did, tag_name="input", interactable=decoys_interactable) for did in ("aAAB", "aAAD", "aAAE")+ ]+ iframe = _static(element_id="AADO", tag_name="iframe", interactable=False, children=[real, *decoys])+ wrapper_div = _static(element_id="AADN", tag_name="div", interactable=False, children=[iframe])+ return _el(wrapper_div)+++async def test_helper_retargets_statically_disabled_single_input() -> None:+ # Scrape-time disabled unique input: the single-chain walk must still surface it, so the retarget+ # picks the real field rather than bailing to the non-fillable wrapper.+ parent = _nested_secure_field_wrapper_disabled_real(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True, disabled=True))+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is child+ assert action.element_id == "aAAC"+ dom.safe_get_skyvern_element_by_id.assert_awaited_once_with("aAAC")+++async def test_helper_still_bails_on_ambiguous_disabled_candidates() -> None:+ # Allowing a disabled candidate must not defeat the fail-closed ambiguity guard: a disabled real+ # input plus interactable decoy siblings are separate branches -> no unambiguous target -> reject.+ parent = _nested_secure_field_wrapper_disabled_real(decoys_interactable=True)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock()+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is None+ assert action.element_id == "AADN"+ dom.safe_get_skyvern_element_by_id.assert_not_called()+++async def test_helper_bails_when_child_hidden() -> None:+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True), hidden=True)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is None+ assert action.element_id == "AADN"+++async def test_helper_bails_when_child_missing() -> None:+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=None)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is None+ assert action.element_id == "AADN"+++async def test_helper_bails_when_child_not_visible() -> None:+ # Time drift: a sole nested candidate with no hidden attrs can still become CSS-hidden+ # (display:none/visibility:hidden) after scrape. Fail closed rather than type the card into it.+ # (has_hidden_attr is False here, so the reject is driven purely by the rendered-visibility gate.)+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True), visible=False)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is None+ assert action.element_id == "AADN"+++async def test_helper_retargets_when_child_visible() -> None:+ # Positive path: a rendered-visible, unambiguous nested input is still retargeted.+ parent = _nested_secure_field_wrapper(decoys_interactable=False)+ child = _stub_child(_static(element_id="aAAC", tag_name="input", interactable=True), visible=True)+ dom = MagicMock()+ dom.safe_get_skyvern_element_by_id = AsyncMock(return_value=child)+ action = MagicMock()+ action.element_id = "AADN"++ result = await _retarget_wrapper_for_input_text(dom, parent, action)++ assert result is child+ assert action.element_id == "aAAC"diff --git a/tests/unit/test_invalid_element_for_text_input_hint.py b/tests/unit/test_invalid_element_for_text_input_hint.pyindex 48865f66c..9b586c76c 100644--- a/tests/unit/test_invalid_element_for_text_input_hint.py+++ b/tests/unit/test_invalid_element_for_text_input_hint.py@@ -130,6 +130,7 @@ def _mock_span_segment_element() -> MagicMock:el.is_spinbtn_input = AsyncMock(return_value=False)el.is_editable = AsyncMock(return_value=False)el.supports_text_input = AsyncMock(return_value=False)+ el.find_deepest_interactable_descendant_in_single_chain = MagicMock(return_value=None)el.is_visible = AsyncMock(return_value=True)el.is_raw_input = AsyncMock(return_value=False)el.is_auto_completion_input = AsyncMock(return_value=False)@@ -227,6 +228,7 @@ def _mock_iframe_element(*, hidden: bool = False) -> MagicMock:el.get_locator.return_value = locatorel.is_disabled = AsyncMock(return_value=False)el.supports_text_input = AsyncMock(return_value=False)+ el.find_deepest_interactable_descendant_in_single_chain = MagicMock(return_value=None)el.get_selectable = AsyncMock(return_value=False)el.has_hidden_attr = AsyncMock(return_value=hidden)el.is_readonly = AsyncMock(return_value=False)diff --git a/tests/unit/test_multi_field_totp.py b/tests/unit/test_multi_field_totp.pyindex 84be98869..f6586c6c7 100644--- a/tests/unit/test_multi_field_totp.py+++ b/tests/unit/test_multi_field_totp.py@@ -299,6 +299,7 @@ async def test_selectable_input_receives_generated_totp_instead_of_marker(monkeyelement.get_frame.return_value = MagicMock()element.get_selectable = AsyncMock(return_value=True)element.is_disabled = AsyncMock(return_value=False)+ element.supports_text_input = AsyncMock(return_value=True)dom = MagicMock()dom.get_skyvern_element_by_id = AsyncMock(return_value=element)dom_type = MagicMock(return_value=dom)diff --git a/tests/unit/test_select_shadow_match.py b/tests/unit/test_select_shadow_match.pyindex 96eea24aa..5f587648f 100644--- a/tests/unit/test_select_shadow_match.py+++ b/tests/unit/test_select_shadow_match.py@@ -1081,7 +1081,11 @@ async def test_execution_disabled_reads_precommit_state_without_clicking(@pytest.mark.asyncioasync def test_converted_route_reports_input_text_converted(monkeypatch: pytest.MonkeyPatch) -> None:- element = MagicMock(is_disabled=AsyncMock(return_value=False), get_selectable=AsyncMock(return_value=True))+ element = MagicMock(+ is_disabled=AsyncMock(return_value=False),+ get_selectable=AsyncMock(return_value=True),+ supports_text_input=AsyncMock(return_value=True),+ )element.get_tag_name.return_value, element.get_id.return_value = "input", "field"monkeypatch.setattr(handler, "DomUtil", Mock(return_value=MagicMock(get_skyvern_element_by_id=AsyncMock(return_value=element)))