From d9e67694945ba739deae661813ab82eec46d4a00 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 2 Sep 2024 11:59:34 +0530 Subject: [PATCH] feat: get children selectors of each gen selector --- server/src/workflow-management/selector.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/src/workflow-management/selector.ts b/server/src/workflow-management/selector.ts index 1941e49d..8f5d2cf8 100644 --- a/server/src/workflow-management/selector.ts +++ b/server/src/workflow-management/selector.ts @@ -759,7 +759,6 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates while (element && element !== document.body && depth < maxDepth) { const selector = getNonUniqueSelector(element); - path.unshift(selector); element = element.parentElement; depth++; @@ -768,12 +767,27 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates return path.join(' > '); } + function getChildSelectors(parent: HTMLElement): string[] { + const childSelectors: string[] = []; + const children = parent.querySelectorAll('*'); + + children.forEach(child => { + const childSelector = getSelectorPath(child as HTMLElement); + childSelectors.push(childSelector); + }); + + return childSelectors; + } + const element = document.elementFromPoint(x, y) as HTMLElement | null; if (!element) return null; const generalSelector = getSelectorPath(element); + const childSelectors = getChildSelectors(element); + return { generalSelector, + childSelectors, }; }, coordinates); @@ -785,6 +799,7 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates }; + /** * Returns the first pair from the given workflow that contains the given selector * inside the where condition, and it is the only selector there.