From 977b976152c60ea98062be6ecb1d3dc83c330a8c Mon Sep 17 00:00:00 2001 From: Mochael Date: Mon, 14 Jul 2025 13:59:53 -0700 Subject: [PATCH 01/11] fixed deepLocator pathing --- lib/handlers/handlerUtils/actHandlerUtils.ts | 73 ++++++++++++-------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/lib/handlers/handlerUtils/actHandlerUtils.ts b/lib/handlers/handlerUtils/actHandlerUtils.ts index c3f9a19b4..1419b75a3 100644 --- a/lib/handlers/handlerUtils/actHandlerUtils.ts +++ b/lib/handlers/handlerUtils/actHandlerUtils.ts @@ -9,37 +9,52 @@ import { StagehandClickError } from "@/types/stagehandErrors"; const IFRAME_STEP_RE = /^iframe(\[[^\]]+])?$/i; export function deepLocator( - root: Page | FrameLocator, - rawXPath: string, -): Locator { - // 1 ─ strip optional 'xpath=' prefix and whitespace - let xpath = rawXPath.replace(/^xpath=/i, "").trim(); - if (!xpath.startsWith("/")) xpath = "/" + xpath; - - // 2 ─ split into steps, accumulate until we hit an iframe step - const steps = xpath.split("/").filter(Boolean); // tokens - let ctx: Page | FrameLocator = root; - let buffer: string[] = []; - - const flushIntoFrame = () => { - if (buffer.length === 0) return; - const selector = "xpath=/" + buffer.join("/"); - ctx = (ctx as Page | FrameLocator).frameLocator(selector); - buffer = []; - }; - - for (const step of steps) { - buffer.push(step); - if (IFRAME_STEP_RE.test(step)) { - // we've included the