feat: paass listSelect
This commit is contained in:
@@ -543,7 +543,7 @@ export class WorkflowGenerator {
|
|||||||
private generateSelector = async (page: Page, coordinates: Coordinates, action: ActionType) => {
|
private generateSelector = async (page: Page, coordinates: Coordinates, action: ActionType) => {
|
||||||
const elementInfo = await getElementInformation(page, coordinates, this.listSelector, this.getList);
|
const elementInfo = await getElementInformation(page, coordinates, this.listSelector, this.getList);
|
||||||
const selectorBasedOnCustomAction = (this.getList === true)
|
const selectorBasedOnCustomAction = (this.getList === true)
|
||||||
? await getNonUniqueSelectors(page, coordinates)
|
? await getNonUniqueSelectors(page, coordinates, this.listSelector)
|
||||||
: await getSelectors(page, coordinates);
|
: await getSelectors(page, coordinates);
|
||||||
|
|
||||||
const bestSelector = getBestSelectorForAction(
|
const bestSelector = getBestSelectorForAction(
|
||||||
|
|||||||
@@ -852,7 +852,7 @@ interface SelectorResult {
|
|||||||
* @returns {Promise<Selectors|null|undefined>}
|
* @returns {Promise<Selectors|null|undefined>}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates): Promise<SelectorResult> => {
|
export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates, listSelector: string): Promise<SelectorResult> => {
|
||||||
try {
|
try {
|
||||||
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 {
|
||||||
@@ -891,24 +891,26 @@ export const getNonUniqueSelectors = async (page: Page, coordinates: Coordinates
|
|||||||
|
|
||||||
let element = originalEl;
|
let element = originalEl;
|
||||||
|
|
||||||
while (element.parentElement) {
|
if (listSelector === '') {
|
||||||
const parentRect = element.parentElement.getBoundingClientRect();
|
while (element.parentElement) {
|
||||||
const childRect = element.getBoundingClientRect();
|
const parentRect = element.parentElement.getBoundingClientRect();
|
||||||
|
const childRect = element.getBoundingClientRect();
|
||||||
const fullyContained =
|
|
||||||
parentRect.left <= childRect.left &&
|
const fullyContained =
|
||||||
parentRect.right >= childRect.right &&
|
parentRect.left <= childRect.left &&
|
||||||
parentRect.top <= childRect.top &&
|
parentRect.right >= childRect.right &&
|
||||||
parentRect.bottom >= childRect.bottom;
|
parentRect.top <= childRect.top &&
|
||||||
|
parentRect.bottom >= childRect.bottom;
|
||||||
const significantOverlap =
|
|
||||||
(childRect.width * childRect.height) /
|
const significantOverlap =
|
||||||
(parentRect.width * parentRect.height) > 0.5;
|
(childRect.width * childRect.height) /
|
||||||
|
(parentRect.width * parentRect.height) > 0.5;
|
||||||
if (fullyContained && significantOverlap) {
|
|
||||||
element = element.parentElement;
|
if (fullyContained && significantOverlap) {
|
||||||
} else {
|
element = element.parentElement;
|
||||||
break;
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user