Javascript 使用Puppeter js按标题查找元素

Javascript 使用Puppeter js按标题查找元素,javascript,node.js,puppeteer,Javascript,Node.js,Puppeteer,使用Puppeter js I在所有元素上循环,如下所示: const getAllElements = await page.$$('._1Nk0C'); for (let [i, link] of getAllElements.entries()) { await link.hover(); await link.screenshot({path: `example${i}.png`}); } 元素内部还有另一个元素,它是一个标题为“下载”的元素。像这

使用Puppeter js I在所有元素上循环,如下所示:

  const getAllElements = await page.$$('._1Nk0C');

  for (let [i, link] of getAllElements.entries()) {
      await link.hover();
      await link.screenshot({path: `example${i}.png`});
  }
元素内部还有另一个元素,它是一个标题为“下载”的元素。像这样:

<a title="Download photo" href="https://example.com/df.jpg/download?force=true" rel="nofollow" download="" target="_blank" class="_1QwHQ"></a>
这给了我一个错误:

UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: document.querySelector is not a function or its return value is not iterable

如何获取该元素?

您可以在
链接上调用
$
变量:

let linkPhoto=wait link.$('a[title=“Download photo”]”);

如果打开DevTools并在控制台中粘贴
[…document.querySelector('a[title=“Download photo”]”)]
,则会出现该错误。为什么要返回一个数组?我不想只得到一个数组中的单个元素。我以为querySelector会找到我所在街区的那个@硬柯德
UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: document.querySelector is not a function or its return value is not iterable