--- id: "e163e999-8d63-4fa0-bca9-6bf1485a19b8" name: "Existing Text Replacement" micro_summary: "Verified one-line replacement: enter the existing box, visibly select the line, Backspace it, type replacement, Escape, then poll for Saved to Drive." status: "resolved" see_also: [] scope: "Verified runbook for replacing the complete contents of an existing one-line Google Slides text box through browser-harness without creating a second box or appending duplicate text." warnings: "Verified only for replacing a complete one-line text box. Before deletion, require screenshots showing the caret in the intended box and exactly the intended line selected. `click_at_xy()` uses CSS pixels, and `type_text()` must follow an explicit `Backspace`." --- ## Reuse the authenticated tab ```bash browser-harness <<'PY' tabs = [t for t in list_tabs() if "docs.google.com/presentation/" in t.get("url", "")] if not tabs: raise RuntimeError("No authenticated Google Slides tab is open") switch_tab(tabs[0]) wait(1) print(capture_screenshot()) PY ``` If the wrong slide is active, press `Escape` to leave text editing, then move one slide at a time with `press_key("PageDown")` or `press_key("PageUp")`. Capture a screenshot and verify the ordinal thumbnail highlight; the URL slide ID is not the ordinal. ## Convert screenshot coordinates to click coordinates `capture_screenshot()` is device-pixel sized while `click_at_xy()` takes CSS pixels. Read the scale: ```bash browser-harness <<'PY' print(js("window.innerWidth + \",\" + window.innerHeight + \",\" + window.devicePixelRatio")) print(capture_screenshot()) PY ``` For an original screenshot coordinate `(sx, sy)`, use `X = sx / devicePixelRatio`, `Y = sy / devicePixelRatio`. Do not use the image viewer's display scaling. ## Enter and verify the existing box ```bash browser-harness <<'PY' click_at_xy(X, Y, clicks=2) wait(.5) print(capture_screenshot()) PY ``` STOP unless the screenshot shows a caret inside the intended existing text box. ## Select and verify the one line ```bash browser-harness <<'PY' press_key("Home") press_key("End", modifiers=8) wait(.3) print(capture_screenshot()) PY ``` `modifiers=8` is Shift. STOP unless the screenshot highlights exactly the full intended line. ## Delete, replace, and verify persistence ```bash browser-harness <<'PY' press_key("Backspace") type_text("REPLACEMENT TEXT") press_key("Escape") status = "" for _ in range(15): wait(1) status = js("""(function(){return [...document.querySelectorAll("[aria-label]")].map(e=>e.getAttribute("aria-label")).find(x=>x&&x.startsWith("Document status:"))||""})()""") if "Saved to Drive" in status: break assert "Saved to Drive" in status, status print(status) print(capture_screenshot()) PY ``` The explicit `Backspace` is load-bearing: CDP `type_text()` uses text insertion and did not replace Google Slides' visually selected text in the verified session.