Hi all, I am going to download PDF file automatically when I click the button. I implemented this using Selenium before but now I want to do this using playwright. Now when I click the button, internal PDF viewer opens it with a new browser. So I think if I make the internal PDF viewer disabled, it is possible to download PDF file automatically, am I right?
This is my selenium code.
chromeOptions = webdriver.ChromeOptions() prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]} # Here should be a list chromeOptions.add_experimental_option("prefs",prefs) chromedriver = "path/to/chromedriver.exe" driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
How to do with playwright? I am working with this for 3 days but not resolved. I am looking forward to your kind replies.
Kind regards!
This thread is trying to answer question "How can I download PDF files automatically using Playwright?"
This feature request contains some useful information: https://github.com/microsoft/playwright/issues/7822
It also contains a workaround for Chromium (sorry it's JavaScript, somebody else will have to translate to Python):
await page.route('**/empty.pdf', async route => {
const response = await page.context().request.get(route.request());
await route.fulfill({
response,
headers: {
...response.headers(),
'Content-Disposition': 'attachment',
}
});
});
So it:
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].