首页 > 解决方案 > Puppeteer page.evalute 找不到块范围变量

问题描述

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 无法访问块范围变量、选择器和 textTarget。

标签: node.jsautomationscopeundefinedpuppeteer

解决方案


推荐阅读