chore: lint
This commit is contained in:
@@ -53,16 +53,16 @@ export const getElementInformation = async (
|
|||||||
info.url = (element as HTMLAnchorElement).href;
|
info.url = (element as HTMLAnchorElement).href;
|
||||||
info.innerText = element.innerText ?? '';
|
info.innerText = element.innerText ?? '';
|
||||||
} else if (element?.tagName === 'IMG') {
|
} else if (element?.tagName === 'IMG') {
|
||||||
info.imageUrl = (element as HTMLImageElement).src;
|
info.imageUrl = (element as HTMLImageElement).src;
|
||||||
} else if (element?.tagName === 'SELECT') {
|
} else if (element?.tagName === 'SELECT') {
|
||||||
const selectElement = element as HTMLSelectElement;
|
const selectElement = element as HTMLSelectElement;
|
||||||
info.innerText = selectElement.options[selectElement.selectedIndex]?.text ?? '';
|
info.innerText = selectElement.options[selectElement.selectedIndex]?.text ?? '';
|
||||||
info.attributes = {
|
info.attributes = {
|
||||||
...info.attributes,
|
...info.attributes,
|
||||||
selectedValue: selectElement.value,
|
selectedValue: selectElement.value,
|
||||||
};
|
};
|
||||||
} else if (element?.tagName === 'INPUT' && (element as HTMLInputElement).type === 'time' || (element as HTMLInputElement).type === 'date') {
|
} else if (element?.tagName === 'INPUT' && (element as HTMLInputElement).type === 'time' || (element as HTMLInputElement).type === 'date') {
|
||||||
info.innerText = (element as HTMLInputElement).value;
|
info.innerText = (element as HTMLInputElement).value;
|
||||||
} else {
|
} else {
|
||||||
info.hasOnlyText = element?.children?.length === 0 &&
|
info.hasOnlyText = element?.children?.length === 0 &&
|
||||||
element?.innerText?.length > 0;
|
element?.innerText?.length > 0;
|
||||||
@@ -865,118 +865,118 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
|
|||||||
try {
|
try {
|
||||||
if (!listSelector) {
|
if (!listSelector) {
|
||||||
console.log(`NON UNIQUE: MODE 1`)
|
console.log(`NON UNIQUE: MODE 1`)
|
||||||
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
|
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
|
||||||
function getNonUniqueSelector(element: HTMLElement): string {
|
function getNonUniqueSelector(element: HTMLElement): string {
|
||||||
let selector = element.tagName.toLowerCase();
|
let selector = element.tagName.toLowerCase();
|
||||||
|
|
||||||
if (element.className) {
|
if (element.className) {
|
||||||
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
||||||
if (classes.length > 0) {
|
if (classes.length > 0) {
|
||||||
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
||||||
if (validClasses.length > 0) {
|
if (validClasses.length > 0) {
|
||||||
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
return selector;
|
function getSelectorPath(element: HTMLElement | null): string {
|
||||||
}
|
const path: string[] = [];
|
||||||
|
let depth = 0;
|
||||||
|
const maxDepth = 2;
|
||||||
|
|
||||||
function getSelectorPath(element: HTMLElement | null): string {
|
while (element && element !== document.body && depth < maxDepth) {
|
||||||
const path: string[] = [];
|
const selector = getNonUniqueSelector(element);
|
||||||
let depth = 0;
|
path.unshift(selector);
|
||||||
const maxDepth = 2;
|
element = element.parentElement;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
while (element && element !== document.body && depth < maxDepth) {
|
return path.join(' > ');
|
||||||
const selector = getNonUniqueSelector(element);
|
|
||||||
path.unshift(selector);
|
|
||||||
element = element.parentElement;
|
|
||||||
depth++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(' > ');
|
const originalEl = document.elementFromPoint(x, y) as HTMLElement;
|
||||||
}
|
if (!originalEl) return null;
|
||||||
|
|
||||||
const originalEl = document.elementFromPoint(x, y) as HTMLElement;
|
let element = originalEl;
|
||||||
if (!originalEl) return null;
|
|
||||||
|
|
||||||
let element = originalEl;
|
// if (listSelector === '') {
|
||||||
|
|
||||||
// if (listSelector === '') {
|
|
||||||
while (element.parentElement) {
|
while (element.parentElement) {
|
||||||
const parentRect = element.parentElement.getBoundingClientRect();
|
const parentRect = element.parentElement.getBoundingClientRect();
|
||||||
const childRect = element.getBoundingClientRect();
|
const childRect = element.getBoundingClientRect();
|
||||||
|
|
||||||
const fullyContained =
|
const fullyContained =
|
||||||
parentRect.left <= childRect.left &&
|
parentRect.left <= childRect.left &&
|
||||||
parentRect.right >= childRect.right &&
|
parentRect.right >= childRect.right &&
|
||||||
parentRect.top <= childRect.top &&
|
parentRect.top <= childRect.top &&
|
||||||
parentRect.bottom >= childRect.bottom;
|
parentRect.bottom >= childRect.bottom;
|
||||||
|
|
||||||
const significantOverlap =
|
const significantOverlap =
|
||||||
(childRect.width * childRect.height) /
|
(childRect.width * childRect.height) /
|
||||||
(parentRect.width * parentRect.height) > 0.5;
|
(parentRect.width * parentRect.height) > 0.5;
|
||||||
|
|
||||||
if (fullyContained && significantOverlap) {
|
if (fullyContained && significantOverlap) {
|
||||||
element = element.parentElement;
|
element = element.parentElement;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const generalSelector = getSelectorPath(element);
|
const generalSelector = getSelectorPath(element);
|
||||||
return {
|
return {
|
||||||
generalSelector,
|
generalSelector,
|
||||||
};
|
};
|
||||||
}, coordinates);
|
}, coordinates);
|
||||||
return selectors || { generalSelector: '' };
|
return selectors || { generalSelector: '' };
|
||||||
} else {
|
} else {
|
||||||
console.log(`NON UNIQUE: MODE 2`)
|
console.log(`NON UNIQUE: MODE 2`)
|
||||||
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
|
const selectors = await page.evaluate(({ x, y }: { x: number, y: number }) => {
|
||||||
function getNonUniqueSelector(element: HTMLElement): string {
|
function getNonUniqueSelector(element: HTMLElement): string {
|
||||||
let selector = element.tagName.toLowerCase();
|
let selector = element.tagName.toLowerCase();
|
||||||
|
|
||||||
if (element.className) {
|
if (element.className) {
|
||||||
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
||||||
if (classes.length > 0) {
|
if (classes.length > 0) {
|
||||||
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
||||||
if (validClasses.length > 0) {
|
if (validClasses.length > 0) {
|
||||||
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
return selector;
|
function getSelectorPath(element: HTMLElement | null): string {
|
||||||
}
|
const path: string[] = [];
|
||||||
|
let depth = 0;
|
||||||
|
const maxDepth = 2;
|
||||||
|
|
||||||
function getSelectorPath(element: HTMLElement | null): string {
|
while (element && element !== document.body && depth < maxDepth) {
|
||||||
const path: string[] = [];
|
const selector = getNonUniqueSelector(element);
|
||||||
let depth = 0;
|
path.unshift(selector);
|
||||||
const maxDepth = 2;
|
element = element.parentElement;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
while (element && element !== document.body && depth < maxDepth) {
|
return path.join(' > ');
|
||||||
const selector = getNonUniqueSelector(element);
|
|
||||||
path.unshift(selector);
|
|
||||||
element = element.parentElement;
|
|
||||||
depth++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(' > ');
|
const originalEl = document.elementFromPoint(x, y) as HTMLElement;
|
||||||
}
|
if (!originalEl) return null;
|
||||||
|
|
||||||
const originalEl = document.elementFromPoint(x, y) as HTMLElement;
|
let element = originalEl;
|
||||||
if (!originalEl) return null;
|
|
||||||
|
|
||||||
let element = originalEl;
|
const generalSelector = getSelectorPath(element);
|
||||||
|
return {
|
||||||
const generalSelector = getSelectorPath(element);
|
generalSelector,
|
||||||
return {
|
};
|
||||||
generalSelector,
|
}, coordinates);
|
||||||
};
|
return selectors || { generalSelector: '' };
|
||||||
}, coordinates);
|
}
|
||||||
return selectors || { generalSelector: '' };
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in getNonUniqueSelectors:', error);
|
console.error('Error in getNonUniqueSelectors:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user