← Back to Discord Forum

please help me rename my download

I am having a really tough time renaming 4 files downloaded using playwright to my custom names. The files have to end in ".csv" for them to be accepted into a google docs clone Im using. I have used suggested filename but it renames all four to the exact same name and then when uploading them to the google docs clone it gets them confused. I tried an object literal like:

const filePath4 = 4${download4.suggestedFilename()} However I get an error saying this path doesnt exist. Does anyone know how I could rename my file to a custom name?

This thread is trying to answer question "How can I rename my downloaded files to custom names using Playwright?"

1 reply

Please don't post the same question over and over seems 56minutes, 8h ago, and 15h ago. Remember this isn't a paid service, generally speaking for myself, will put in as much effort as you to help solve it as you put in yourself. To that end where is the source of what you've tried? Oh good rule of thumb never call out and direct messages at a person, to get there attention, thankfully discord has a block/mute user... Being lazy and/or pushy === Mute. Just speaking for myself. I remeber BBS systems from the 80's might take days or a week or longer to get a response...


Sure, you can rename your downloaded files using Playwright. It's as easy as using the saveAs() method from the Download object. This method lets you specify a custom path where the download should be copied. By changing the file name in the path, you can rename the downloaded file.

Here's a quick example:

const downloadPromise = page.waitForEvent('download');
await page.getByText('Download file').click();
const download = await downloadPromise;

// Specify a custom path with a different file name
await download.saveAs('/path/to/save/custom_name.txt');

In this code, we start the download by clicking on an element with the text "Download file". We then wait for the 'download' event using waitForEvent(). Once the event is triggered, we get the Download object (download). We then use saveAs() to specify a custom path (/path/to/save/) and a new file name (custom_name.txt). The downloaded file will be saved with this new name at the specified location.

Remember to replace /path/to/save/ with your desired directory path and "custom_name.txt" with your preferred custom name for each downloaded file.

And that's it! You've just renamed your downloaded files using Playwright.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.