From fda1027ef635156670fea3af06193d99d5c291dd Mon Sep 17 00:00:00 2001 From: Bram Date: Thu, 2 Apr 2026 09:43:44 +0200 Subject: [PATCH] element from point potential fix --- Dockers/puppeteer-api/app/services/browser.py | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Dockers/puppeteer-api/app/services/browser.py b/Dockers/puppeteer-api/app/services/browser.py index b90b66f..2fc4533 100644 --- a/Dockers/puppeteer-api/app/services/browser.py +++ b/Dockers/puppeteer-api/app/services/browser.py @@ -282,29 +282,37 @@ async def interactions_service( elif x is not None and y is not None: if action == "click": # Use DOM elementFromPoint so React/SPA components receive real click events. - handle = await page.evaluate_handle( - "(cx, cy) => document.elementFromPoint(cx, cy)", - x, - y, - ) try: - await handle.click() + handle = await page.evaluate_handle( + f"document.elementFromPoint({x}, {y})" + ) + element = handle.as_element() + if element is None: + raise ValueError(f"No element found at coordinates ({x}, {y})") + await element.click() finally: - await handle.dispose() + try: + await handle.dispose() + except Exception: + pass elif action == "type": if text is None: raise ValueError("Type interaction must contain text") # Focus the element at the given coordinates, then type. - handle = await page.evaluate_handle( - "(cx, cy) => document.elementFromPoint(cx, cy)", - x, - y, - ) try: - await handle.click() + handle = await page.evaluate_handle( + f"document.elementFromPoint({x}, {y})" + ) + element = handle.as_element() + if element is None: + raise ValueError(f"No element found at coordinates ({x}, {y})") + await element.click() finally: - await handle.dispose() + try: + await handle.dispose() + except Exception: + pass await page.keyboard.type(text) else: