[Question] about downloads with launchPersistentContext
See original GitHub issueHello I am writing a script in which i log in to a page, and download some files.
Here is how the download works: I press the button with the text “Gem” which opens a target_blank page which downloads the file, and that page then closes.
<button tabindex="0" class="button ng-scope focusable" data-ng-click="save()" data-translate="" title="Gem">Gem</button>
Clicking the “Gem” button opens up the url from the following forms action
<form id="downloadForm" action="api_eb/documents/download" method="post" target="_blank" style="display: none;"> <input type="hidden" name="useMediaType" value="false" tabindex="-1"></form>
The download happens but the script freezes after the first downloaded file. Removing const dl = await download.path();
makes it so the script finishes entirely and downloads both files, BUT THE FILES ARE DELETED WHEN THE BROWSER CONTEXT IS CLOSED.
How do i solve this? Help would be much appreciated!!!
const { chromium } = require('playwright');
let { PythonShell } = require('python-shell')
const path = require('path');
const eboks = async () => {
const pathToExtension = require('path').join(__dirname,'../extensions/nemid');
const userDataDir = path.join(__dirname, '../extensions/nemid/userdata');
const browser = await chromium.launchPersistentContext(userDataDir,{
headless: false,
slowMo: 1000,
acceptDownloads: true,
downloadsPath: 'C:\\Users\\mbe\\Downloads',
args:[
`--disable-extensions-except=${path.join(__dirname, '../extensions/nemid')}`,
`--load-extension=${path.join(__dirname, '../extensions/nemid')}`
]
});
// Test the background page
const backgroundPage = browser.backgroundPages()[0];
const page = await browser.newPage();
// Download ------------------------------------------------------------------------------------------------------------>
// I AM ALREADY ON THE REQUIRED PAGE AND LOGGED IN
const accounts = ['NEXT Forsikring A/S - Forsikringsformidling', 'PI Applications A/S - 34043027'];
for (const account of accounts) {
await page.click('.mailboxMenuUsers');
await page.click(`text=${account}`);
await page.click('text=Sparekassen');
await page.click('text=Vælg alle');
await page.click('a[role="link"]:has-text("Mere")');
await page.click('text=Gem en lokal kopi');
await page.click('text=Gem alle');
const [ download ] = await Promise.all([
// Start waiting for the download
page.waitForEvent('download'),
// Perform the action that initiates download
page.click('button:has-text("Gem")'), // Clicking the button opens an external window that downloads the file and then closes the window.
]);
// const dl = await download.path(); WITH THIS ENABLED THE SCRIPT FREEZES AFTER THE FIRST DOWNLOAD
}
await browser.close();
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Download files in Playwright with proper file name
download.suggestedFilename() but with this I have error suggestedFilename is not a function. I run browser with launchPersistentContext option ...
Read more >Playwright changelog - Awesome Node.js - LibHunt
#4319 - [Question] Have the browsers that are downloaded for playwright 1.3.0 ... launchPersistentContext() now support videosPath and videoSize option.
Read more >Using Kameleo with Playwright framework
launchPersistentContext ('', { // The Playwright framework is not designed to connect to already running // browsers.
Read more >Release notes | Playwright
Selector ambiguity is a common problem in automation testing. ... launchPersistentContext(userDataDir[, options]); new browserContext.tracing API namespace ...
Read more >Releases
... [Playwright] Implemented launchPersistentContext to be able to launch persistent remote ... removed question on "steps file", create it by default.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed, validated with playwright@next. Thank you 😃
Should be fixed by #6082, can you validate the fix with playwright@next?