function clickElement(page, selector, textTarget) {
page.evaluate(() => {
[...document.querySelectorAll(selector)]
.find((element) => element.textContent === textTarget)
.click();
console.log(selector,textTarget)
// selector and textTarget is undefined
});
}
page.evaluate cannot access block scope variables, selector and textTarget in this example.