javascriptpuppeteerclassname

Puppeteer cannot read a classname with spaces


Someone tell me why puppeteer cannot readme a classname with spaces, but a id or name it's works. I need help, i just make a simple automation.

const puppeteer = require("puppeteer");

(async () => {

    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();


    await page.goto("https://www.reddit.com/")


    await page.click("._3Wg53T10KuuPmyWOMWsY2F Z_HUY3BUsGOBOtdmH94ZS q_unSaY23rpdd3lDvGZ- _2iuoyPiKHN3kfOoeIQalDT _10BQ7pjWbeYP63SAPNS8Ts HNozj_dKjQZ59ZsfEegz8 _2Z-LWN_PrkTncEM_mPuEW5")

})();

Solution

  • In Puppeteer, when using the page.click() method to select an element by its class name, you should not include any spaces between the class names. Instead, you should concatenate the class names together without spaces.

    You should write:

    await page.click("._3Wg53T10KuuPmyWOMWsY2F.Z_HUY3BUsGOBOtdmH94ZS.q_unSaY23rpdd3lDvGZ-._2iuoyPiKHN3kfOoeIQalDT._10BQ7pjWbeYP63SAPNS8Ts.HNozj_dKjQZ59ZsfEegz8._2Z-LWN_PrkTncEM_mPuEW5")