I'm attempting to click on an href in puppeteer js.
Here is my code:
await page.goto('https://example.net/search/images?search=real+estate+postcards');
await page.waitForSelector(".GridItem-item-tVq", {visible: true});
const els = await page.$$(".GridItem-item-tVq");
els.forEach(async el => {
const href = await el.$eval('a', a => a.getAttribute('href'));
await page.click(href)
})
when I console.log href I get:
/gallery/93911757/High-End-Real-Estate-Postcard-Design/modules/542619723
/gallery/69359021/Postcard-Design/modules/492523237
/gallery/158597277/Post-Card-Design/modules/894845353
/gallery/126032017/Real-Estate-Agent-Postcard/modules/715550465
This is a url in example.com so in example: example.com/gallery/93911757/High-End-Real-Estate-Postcard-Design/modules/542619723 would go to the page.
I attempt to click on it with this:
els.forEach(async el => {
const href = await el.$eval('a', a => a.getAttribute('href'));
await page.click(href)
})
'Document': '/gallery/93911757/High-End-Real-Estate-Postcard-Design/modules/542619723' is not a valid selector.
Since it says it's not a valid selector I run. I also try:
await page.click(el)
But it gives me an error.
error: selector.startsWith is not a function
Obviously I'm not getting the correct element but how can I get the 'a' to click it?