diff --git a/server/src/workflow-management/classes/Generator.ts b/server/src/workflow-management/classes/Generator.ts index 312f8a2a..cfef4a30 100644 --- a/server/src/workflow-management/classes/Generator.ts +++ b/server/src/workflow-management/classes/Generator.ts @@ -160,6 +160,41 @@ export class WorkflowGenerator { }) }; + /** + * New function to handle actionable check for scrapeList + * @param page The current Playwright Page object. + * @param config The scrapeList configuration object. + * @returns {Promise} Array of actionable selectors. + */ + private async getSelectorsForScrapeList(page: Page, config: { + listSelector: string; + fields: any; + limit?: number; + pagination: any; + }): Promise { + const { listSelector } = config; + + // Verify if the selectors are present and actionable on the current page + const actionableSelectors: string[] = []; + if (listSelector) { + const isActionable = await page.isVisible(listSelector).catch(() => false); + if (isActionable) { + actionableSelectors.push(listSelector); + logger.log('debug', `List selector ${listSelector} is actionable.`); + } else { + logger.log('warn', `List selector ${listSelector} is not visible on the page.`); + } + } + + return actionableSelectors; + } + + /** + * New function to handle actionable check for scrapeList + * @param page The current Playwright Page object. + * @param schema The scrapeSchema configuration object. + * @returns {Promise} Array of actionable selectors. + */ private async getSelectorsForSchema(page: Page, schema: Record): Promise { const selectors = Object.values(schema).map((field) => field.selector); @@ -208,6 +243,14 @@ export class WorkflowGenerator { pair.where.selectors = [...(pair.where.selectors || []), ...additionalSelectors]; } } + + if (pair.what[0].action === 'scrapeList') { + const config = pair.what[0]?.args?.[0]; + if (config) { + const actionableSelectors = await this.getSelectorsForScrapeList(page, config); + pair.where.selectors = [...(pair.where.selectors || []), ...actionableSelectors]; + } + } // Validate if the pair is already in the workflow if (pair.where.selectors && pair.where.selectors[0]) {