From 7d3bd22cd41e63149a2c4d8b6b7e198ec7df3c33 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 5 Jun 2024 06:26:13 +0530 Subject: [PATCH] feat: find the HTML element at the specified coordinates + cast it to an HTMLElement type --- server/src/workflow-management/selector.ts | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/src/workflow-management/selector.ts diff --git a/server/src/workflow-management/selector.ts b/server/src/workflow-management/selector.ts new file mode 100644 index 00000000..d16f5cd1 --- /dev/null +++ b/server/src/workflow-management/selector.ts @@ -0,0 +1,34 @@ +import { Page } from "playwright"; +import { Action, ActionType, Coordinates, TagName } from "../types"; +import { WhereWhatPair, WorkflowFile } from "@wbr-project/wbr-interpret"; +import logger from "../logger"; +import { getBestSelectorForAction } from "./utils"; + +/** + * Returns a {@link Rectangle} object representing + * the coordinates, width, height and corner points of the element. + * If an element is not found, returns null. + * @param page The page instance. + * @param coordinates Coordinates of an element. + * @category WorkflowManagement-Selectors + * @returns {Promise} + */ +export const getRect = async (page: Page, coordinates: Coordinates) => { + try { + const rect = await page.evaluate( + async ({ x, y }) => { + const el = document.elementFromPoint(x, y) as HTMLElement; + ); + + } catch (error) { + const { message, stack } = error as Error; + logger.log('error', `Error while retrieving selector: ${message}`); + logger.log('error', `Stack: ${stack}`); + } +} + + + + + +