feat: get children selectors of each gen selector

This commit is contained in:
karishmas6
2024-09-02 11:59:34 +05:30
parent ab7f5f969b
commit d9e6769494

View File

@@ -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.