import type PageOptions from '../types/PageOptions'; import getPage from './getPage'; /** * Click on the node that has a specific text content based on its selector. * @param {string} selector The selector that will select multiple nodes. * @param {string} text The text used to discriminate the nodes. * @param {PageOptions} options * @returns {Promise} */ export default async function clickByText(selector: string, text: string, options?: PageOptions) { const page = getPage(options); await page.waitForSelector(selector); await page.evaluate<(args: { selector: string; text: string }) => void>( ({ selector, text }) => { const nodes = document.querySelectorAll(selector); const found = Array.from(nodes).find((selector) => selector.innerText === text); found?.click(); }, { selector, text }, ); }