Getting a list of list elements using Playwright

I am trying to write an application where it will go to amazon and get a list of books on the page. I am using Playwright as the tool. I can get to the right section but I can’t get the list of books. Looking online the examples seem to use page.$$(selector) but when I try that, I get an empty array back. Found this information here and here. Reading the docs on $$, this seems like the right call as all the list elements have the same class name. I have no idea what I am doing wrong, any advice on this?

Here is my code so far;

const AMAZON_KINDLE_EBOOK_STORE_URL = 'https://www.amazon.com/Best-Sellers-Kindle-Store-eBooks/zgbs/digital-text/154606011/ref=zg_bs_nav_kstore_1_kstore/';
(async () => {
    const browser = await chromium.launch();
    try {
        const amazonPage = await browser.newPage();
        await amazonPage.goto(AMAZON_KINDLE_EBOOK_STORE_URL);

        await amazonPage.waitForSelector('"Best Sellers in"');
        await amazonPage.click('"Self-Help"');
        await amazonPage.click('"Creativity"')

        const books = await amazonPage.$$('li[class="zg-item-immersion"]');
        console.log(books);
    } finally {
        await browser.close();
    }
})();

For the selector I have tried it numerous ways as well;

  • li[class="zg-item-immersion"] – This actually worked checking on the dev console
  • 'zg-item-immersion'
  • #zg-item-immersion

54 thoughts on “Getting a list of list elements using Playwright”

  1. Pingback: generic viagra
  2. Pingback: viagra online usa
  3. Pingback: herbal viagra
  4. Pingback: sildenafil online
  5. Pingback: cialis price
  6. Pingback: canadian viagra
  7. Pingback: cheap viagra

Leave a Comment