Reputation: 3320
Using puppeteer js I loop over all elements like so:
const getAllElements = await page.$$('._1Nk0C');
for (let [i, link] of getAllElements.entries()) {
await link.hover();
await link.screenshot({path: `example${i}.png`});
}
Inside of the element there's another element which is an with a title of "download". Like so:
<a title="Download photo" href="https://example.com/df.jpg/download?force=true" rel="nofollow" download="" target="_blank" class="_1QwHQ"></a>
I need to get that element so I can click on it. I tried this:
for (let [i, link] of getAllElements.entries()) {
await link.hover();
await link.screenshot({path: `example${i}.png`});
const download = await page.evaluate(() => [...document.querySelector('a[title="Download photo"]')])
console.log(download);
}
This gave me an error:
UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: document.querySelector is not a function or its return value is not iterable
How can I do it to get that element?
Upvotes: 2
Views: 1010
Reputation: 21705
You can call $
on your link
variable:
let linkPhoto = await link.$('a[title="Download photo"]');
Upvotes: 2