My HTML code looks like this:
<div class="class1" data-id="id1">
<span class="class2">
"text1"
</span>
</div>
<div class="class1" data-id="id2">
<span class="class2">
"text2"
</span>
</div>
<div class="class1" data-id="id1">
<span class="class2">
"text1"
</span>
</div>
<div class="class1" data-id="id3">
<span class="class2">
"text3"
</span>
</div>
I'm trying to write Puppetteer code to get the data-id and span inner text pairs, which would result in something like:
id1: text1,
id2: text2,
id3: text3
What I tried:
const allClass1InPage = await this.page.$$(".class1");
for (const class1El of allClass1InPage) {
await elem.$eval(".class2", (class2El) =>
console.debug(`${???}: ${???}`)
);
}
What I don't know is:
- How to get the
data-idout of anElementHandle(asclass1El, normally I would do.dataset.idif it was anElementinstead)? - Why I'm getting `UnhandledPromiseRejectionWarning: Error: Error: failed to find element matching selector ".class2"?