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

313
Views
How can you click on the download button on a PDF page with Puppeteer?

I'm on a PDF page in my browser and I'm trying to click on the download button on the top right corner. This picture is added for clarity. I've tried right clicking on the button, grabbing both the CSS selector and the XPath but in my code, it doesn't show up as an element. What am I doing wrong?

enter image description here

This is my code for reference.

page.goto(url);
page.click([link that opens up new tab]);
const [tab1, tab2, tab3] = await browser.pages();
await tab3.click("#download");
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I managed to fix my problem by using the second solution posted here: How to download a pdf that opens in a new tab in puppeteer?. Basically, using puppeteer extra, I changed the behavior of clicking the link to trigger the download manually.

puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({
    headless: false, 
    timeout: 30000, 
    ignoreHTTPSErrors: true, 
    userPrefs: {
        download: {
            prompt_for_download: false, 
            open_pdf_in_system_reader: true
        }, 
        plugins: {
            always_open_pdf_externally: true
        }
    } 
}));
let browser = await puppeteer.launch();
let page = await browser.newPage();
...
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'});

Thank you for the help!

about 4 years ago · Juan Pablo Isaza Report

0

You can use this code which is very easy:

from urllib import request

url = 'https://dagrs.berkeley.edu/sites/default/files/2020-01/sample.pdf'
request.urlretrieve(url, 'sample.pdf')
about 4 years ago · Juan Pablo Isaza 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!