Merge branch 'develop' into shadow-dom
This commit is contained in:
@@ -139,26 +139,45 @@ export const getElementInformation = async (
|
||||
const originalEl = getDeepestElementFromPoint(x, y);
|
||||
if (originalEl) {
|
||||
let element = originalEl;
|
||||
|
||||
// Handle element hierarchy traversal for list items
|
||||
while (element.parentElement) {
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
element = element.parentElement;
|
||||
} else {
|
||||
break;
|
||||
|
||||
if (element.tagName === 'TD' || element.tagName === 'TH') {
|
||||
const tableParent = element.closest('table');
|
||||
if (tableParent) {
|
||||
element = tableParent;
|
||||
}
|
||||
}
|
||||
|
||||
if (element.tagName !== 'TABLE') {
|
||||
while (element.parentElement) {
|
||||
if (element.tagName.toLowerCase() === 'body' ||
|
||||
element.tagName.toLowerCase() === 'html') {
|
||||
break;
|
||||
}
|
||||
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
const nextParent = element.parentElement;
|
||||
if (nextParent.tagName.toLowerCase() !== 'body' &&
|
||||
nextParent.tagName.toLowerCase() !== 'html') {
|
||||
element = nextParent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,25 +338,44 @@ export const getRect = async (page: Page, coordinates: Coordinates, listSelector
|
||||
if (originalEl) {
|
||||
let element = originalEl;
|
||||
|
||||
// Handle element hierarchy traversal for list items
|
||||
while (element.parentElement) {
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
if (element.tagName === 'TD' || element.tagName === 'TH') {
|
||||
const tableParent = element.closest('table');
|
||||
if (tableParent) {
|
||||
element = tableParent;
|
||||
}
|
||||
}
|
||||
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
if (element.tagName !== 'TABLE') {
|
||||
while (element.parentElement) {
|
||||
if (element.tagName.toLowerCase() === 'body' ||
|
||||
element.tagName.toLowerCase() === 'html') {
|
||||
break;
|
||||
}
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
element = element.parentElement;
|
||||
} else {
|
||||
break;
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
const nextParent = element.parentElement;
|
||||
if (nextParent.tagName.toLowerCase() !== 'body' &&
|
||||
nextParent.tagName.toLowerCase() !== 'html') {
|
||||
element = nextParent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1113,17 +1151,24 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
|
||||
// Generate basic selector from element's tag and classes
|
||||
function getNonUniqueSelector(element: HTMLElement): string {
|
||||
let selector = element.tagName.toLowerCase();
|
||||
|
||||
const className = typeof element.className === 'string' ? element.className : '';
|
||||
if (className) {
|
||||
const classes = className.split(/\s+/)
|
||||
.filter(cls => Boolean(cls) && !cls.startsWith('!') && !cls.includes(':'));
|
||||
|
||||
|
||||
if (selector === 'td' && element.parentElement) {
|
||||
// Find position among td siblings
|
||||
const siblings = Array.from(element.parentElement.children);
|
||||
const position = siblings.indexOf(element) + 1;
|
||||
return `${selector}:nth-child(${position})`;
|
||||
}
|
||||
|
||||
if (element.className) {
|
||||
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
||||
if (classes.length > 0) {
|
||||
selector += '.' + classes.map(cls => CSS.escape(cls)).join('.');
|
||||
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
||||
if (validClasses.length > 0) {
|
||||
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
@@ -1202,25 +1247,45 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
|
||||
|
||||
let element = originalEl;
|
||||
|
||||
// Handle parent traversal for better element targeting
|
||||
while (element.parentElement) {
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
if (element.tagName === 'TD' || element.tagName === 'TH') {
|
||||
const tableParent = element.closest('table');
|
||||
if (tableParent) {
|
||||
element = tableParent;
|
||||
}
|
||||
}
|
||||
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
// if (listSelector === '') {
|
||||
if (element.tagName !== 'TABLE') {
|
||||
while (element.parentElement) {
|
||||
if (element.tagName.toLowerCase() === 'body' ||
|
||||
element.tagName.toLowerCase() === 'html') {
|
||||
break;
|
||||
}
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
const parentRect = element.parentElement.getBoundingClientRect();
|
||||
const childRect = element.getBoundingClientRect();
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
element = element.parentElement;
|
||||
} else {
|
||||
break;
|
||||
const fullyContained =
|
||||
parentRect.left <= childRect.left &&
|
||||
parentRect.right >= childRect.right &&
|
||||
parentRect.top <= childRect.top &&
|
||||
parentRect.bottom >= childRect.bottom;
|
||||
|
||||
const significantOverlap =
|
||||
(childRect.width * childRect.height) /
|
||||
(parentRect.width * parentRect.height) > 0.5;
|
||||
|
||||
if (fullyContained && significantOverlap) {
|
||||
const nextParent = element.parentElement;
|
||||
if (nextParent.tagName.toLowerCase() !== 'body' &&
|
||||
nextParent.tagName.toLowerCase() !== 'html') {
|
||||
element = nextParent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1260,17 +1325,23 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
|
||||
// Generate basic selector from element's tag and classes
|
||||
function getNonUniqueSelector(element: HTMLElement): string {
|
||||
let selector = element.tagName.toLowerCase();
|
||||
|
||||
const className = typeof element.className === 'string' ? element.className : '';
|
||||
if (className) {
|
||||
const classes = className.split(/\s+/)
|
||||
.filter(cls => Boolean(cls) && !cls.startsWith('!') && !cls.includes(':'));
|
||||
|
||||
|
||||
if (selector === 'td' && element.parentElement) {
|
||||
const siblings = Array.from(element.parentElement.children);
|
||||
const position = siblings.indexOf(element) + 1;
|
||||
return `${selector}:nth-child(${position})`;
|
||||
}
|
||||
|
||||
if (element.className) {
|
||||
const classes = element.className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
||||
if (classes.length > 0) {
|
||||
selector += '.' + classes.map(cls => CSS.escape(cls)).join('.');
|
||||
const validClasses = classes.filter((cls: string) => !cls.startsWith('!') && !cls.includes(':'));
|
||||
if (validClasses.length > 0) {
|
||||
selector += '.' + validClasses.map(cls => CSS.escape(cls)).join('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
@@ -1364,6 +1435,12 @@ export const getChildSelectors = async (page: Page, parentSelector: string): Pro
|
||||
function getNonUniqueSelector(element: HTMLElement): string {
|
||||
let selector = element.tagName.toLowerCase();
|
||||
|
||||
if (selector === 'td' && element.parentElement) {
|
||||
const siblings = Array.from(element.parentElement.children);
|
||||
const position = siblings.indexOf(element) + 1;
|
||||
return `${selector}:nth-child(${position})`;
|
||||
}
|
||||
|
||||
const className = typeof element.className === 'string' ? element.className : '';
|
||||
if (className) {
|
||||
const classes = className.split(/\s+/).filter((cls: string) => Boolean(cls));
|
||||
|
||||
Reference in New Issue
Block a user