Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Find specific divs on page and remove before taking screenshot with puppeteer

I have a node/puppeteer script that visits a page, finds a specific div with a class, and takes a screenshot of the div. However, there are elements/nodes on the page that I'd like to delete before capturing the screenshot since they are interfering with the image, but can't seem to find the documentation on how to do so.

This is what I have so far, but can't figure out when or how to delete a given div with a specific class .ce45 for instance:

await page.setViewport({
    width: 1368,
    height: 768
});
await page.waitForSelector(`.${url.id.toLowerCase()}`).then(() => console.log('scraped', url.id.toLowerCase()));        
const component = await page.$(`.${url.id.toLowerCase()}`);     
const bounding_box = await component.boundingBox();  
await component.screenshot({
   path: `./${url.id.toLowerCase()}.png`,
   clip: {
      x: bounding_box.x,
      y: bounding_box.y,
        width: Math.min(bounding_box.width, page.viewport().width),
        height: Math.min(bounding_box.height, page.viewport().height),
   }
});

I have tried:

await page.evaluate((sel) => {
  let div_selector_to_remove = ['.ce45', '.d20', '.cc27'];
  for(sel of div_selector_to_remove){
     document.querySelector(`${sel}`).remove();
  }
});

but get the error Cannot read properties of null (reading 'remove')

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The way you have it will only remove the first for each selector (and throw error when it's not there).

Try:

page.$$eval('.ce45,.d20,.cc27', els => els.map(el => el.remove()))
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!