Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
How to click on an a tag who's text matches a given string puppeteer

I am trying to write a purchasing bot for supreme website as a way to teach myself javascript and pupetteer. I am having trouble finding a way to click on the item that contains the text that is given as an argument in the function. Here is what I am trying

'''

const puppeteer = require('puppeteer-extra');
const pluginStealth = require("puppeteer-extra-plugin-stealth");
puppeteer.use(pluginStealth());
const BASE_URL = "https://www.supremenewyork.com/shop/all";
const CHECKOUT_URL = "https://www.supremenewyork.com/checkout";

async function startBot(itemCategory) {

    const browser = await puppeteer.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        headless: false 
     });

    let page = await browser.newPage();
    await page.goto(itemCategory);
    return {page};

}

async function closeBrowser(browser) {

    return browser.close();

}

async function addToCart(page, itemName) {
    page.$$eval('a', as => as.find(a => a.innerText.match(itemName).click()));
}

async function checkout() {

    const page = await startBot(categories['t_shirts']);
    await addToCart(page, item_info['name']);

}

checkout();

'''

The error I get is: TypeError: page.$x is not a function

Am I going about this the correct way or is there a better method This is a brief overview of the HTML

<div class="inner-article">
    <a style="height:150px;" href="/shop/t-shirts/kw2h4jdue/dvor2fh76"><img width="150" height="150" src="//assets.supremenewyork.com/231423/vi/u13QfMEqLmM.jpg" alt="U13qfmeqlmm">
    </a>
        <h1>
            <a class="name-link" href="/shop/t-shirts/kw2h4jdue/dvor2fh76">Knowledge Tee
            </a>
        </h1>
         <p>
              <a class="name-link" href="/shop/t-shirts/kw2h4jdue/dvor2fh76">Black
           </a>
         </p>
</div>

I want to click the a class thats text is 'Knowledge Tee'

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

page.$x should be a function I think so something else is going wrong there.

You can also do something like:

page.$$eval('a', as => as.find(a => a.innerText.match("Knowledge Tee").click()))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda