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

314
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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