// Vars const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]'; const CELL_SELECTOR = 'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]'; const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]' const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]' const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]' /** * Extracted function to get the text content of a node. * @param {ElementHandle} node - The node to get the text content from. * @returns {Promise} The text content of the node. */ async function getNodeTextContent(node) { return await node.evaluate((node) => node.textContent); } /** * Extracted function to retrieve the content frame. * @param {Page} page - The Puppeteer page object. * @returns {Promise} The content frame. */ async function getContentFrame(page) { await page.waitForSelector(IFRAME_SELECTOR); const iframe = await page.$(IFRAME_SELECTOR); if (!iframe) { throw new Error("Could not find iframe on the AA-page"); } console.log("iframe found on AA-page"); return await iframe.contentFrame(); } /** * Checks if the 'Startpakket' is available by verifying text content in a cell * and the `aria-expanded` attribute. * * @param {Page} page - The Puppeteer page object. * @returns {Promise} True if the 'Startpakket' is available, false otherwise. */ async function isStartPakketAvailable(page) { const contentFrame = await getContentFrame(page); await contentFrame.waitForSelector(CELL_SELECTOR); const cell = await contentFrame.$(CELL_SELECTOR); const cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR) if (!cell ) { throw new Error( "Cell inside function isStartPakketAvailable is not defined" ); } //object vars const isCollapsed_main = await isAriaExpandedFalse(cell); const isCollapsed_keuze = await getIsCollapsedKeuze(cell_keuze); const isCollapsed = isCollapsed_main && isCollapsed_keuze; const studName = await getStudName(contentFrame); const studId = await getStudId(contentFrame); return { isCollapsed: isCollapsed, isCollapsed_main: isCollapsed_main, isCollapsed_keuze: isCollapsed_keuze, studName: studName, studId: studId, // more properties here }; } /** * Checks if the given cell node has an `aria-expanded` attribute with a value of 'false'. * * @param {ElementHandle} node - The node to check the `aria-expanded` attribute. * @returns {Promise} True if the `aria-expanded` attribute is 'false', false otherwise. */ async function isAriaExpandedFalse(node) { if (!node) { throw new Error("Node is not defined"); } return await node.evaluate( (element) => element.getAttribute("aria-expanded") === "false" ); } async function getIsCollapsedKeuze(cell_keuze) { if (cell_keuze) { return await isAriaExpandedFalse(cell_keuze); } else { return false; } } async function getStudName(frame) { const cell = await frame.$(STUDENT_NAME_CELL_SELECTOR); if (!cell) { throw new Error("Cell student name is not defined"); } return await getNodeTextContent(cell); } async function getStudId(frame) { const cell = await frame.$(STUDENT_ID_CELL_SELECTOR); if (!cell) { throw new Error("Cell student id is not defined"); } return await getNodeTextContent(cell); } module.exports = isStartPakketAvailable;