Limpfro
Limpfro

Reputation: 177

Puppeteer - how to select A tag inside a div with class name

I'm trying to find all elements with a class name that have an A tag inside it

I need to click each element but im having a hard time wondering how

html :

<li class="item-sku-image">
    <a data-role="sku" data-sku-id="10" id="sku-1-10" title="Not print pants 1"
        href="javascript:;" data-spm-anchor-id="2114.10010108.1000016.9">
        <img
            src="https://ae01.alicdn.com/kf/HTB1sV2wMNYaK1RjSZFnq6y80pXam/2019-Naruto-Hoodies-Sweatshirts-Uchiha-Syaringan-Hooded-Boys-Fashion-Hokage-Ninjia-Men-women-Classic-Cartoon-printed.jpg_50x50.jpg"
            title="Not print pants 1"
            bigpic="https://ae01.alicdn.com/kf/HTB1sV2wMNYaK1RjSZFnq6y80pXam/2019-Naruto-Hoodies-Sweatshirts-Uchiha-Syaringan-Hooded-Boys-Fashion-Hokage-Ninjia-Men-women-Classic-Cartoon-printed.jpg_640x640.jpg"
            data-spm-anchor-id="2114.10010108.1000016.i7.46dd1b78TiKxz6"></a>
        </li>

my puppeteer code so far :

await page.evaluate(async () => {
    let elements = document.getElementsByClassName('.item-sku-image');
    console.log(elements)
});

I tried a few other things from stackoverflow's question area but nothing seemed to work.

My core purpose is to click a link (a tag) and then save a few elements on the page then click the next link

Upvotes: 1

Views: 3649

Answers (1)

mepley
mepley

Reputation: 539

let elements = document.querySelectorAll(".item-sku-image a");

Upvotes: 3

Related Questions