Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda