Change download folder and file name on chromedriver

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Change download folder and file name on chromedriver

Post by thiagunix » Wed Mar 31, 2021 3:01 pm

Good morning,

I have a routine where a file is downloaded and imported into another.

Can I determine where the file is going to be saved and what name it should be at the time of download?
I'm using chromedriver.

Today it saves in the default folder of chromedriver (Downloads) with a default name I move and rename to perform the import and this does not work well, always the problem.

Can I download it in the right place with the right name?

Thanks

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Change download folder and file name on chromedriver

Post by Dorian (MJT support) » Thu Apr 01, 2021 10:42 am

I was experimenting with this a little while ago, and didn't manage to find a way. There are some great mind here though, and some of those have delved quite deeply into ChromeDriver options.

I'd be doing it the same way you already are unless someone finds a way to do it. The question in the meantime is, how can we make the method you're using more reliable? What seems to be happening?
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Change download folder and file name on chromedriver

Post by Grovkillen » Thu Apr 01, 2021 3:10 pm

I think you need to tap into some of the experimental options to change that. As far as I've been able to tell it's not possible from the MS commands. But that being said, can't you just monitor the download directory and get the files from there and then move them to wherever you want?
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Change download folder and file name on chromedriver

Post by Grovkillen » Thu Apr 01, 2021 3:18 pm

The file name can be changed using JavaScript. Just add a <a> with href to the file and add the name using the download attribute to specify the file name:

Code: Select all

<a href="https://url.domain/file.abc" download="filename.123">
Just click (using either JS or some MS command) and it will be downloaded as filename.123
Let>ME=%Script%

Running: 15.0.27
version history

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Change download folder and file name on chromedriver

Post by thiagunix » Thu Apr 01, 2021 8:15 pm

I didn't know about these experimental functions, I will research.

Code: Select all

I think you need to tap into some of the experimental options to change that. 
As far as I've been able to tell it's not possible from the MS commands. But that being said, 
can't you just monitor the download directory and get the files from there and then move them to 
wherever you want?
My script downloads the file in the Download folder and in the sequence it takes this file and moves it to the folder where the other routine does the import. The problem is that sometimes the site where he downloads the bug or gets slow and takes a long time to release the download and the script tries to move the file but it is not available yet and proceeds to the next step.

Code: Select all

<a href="https://url.domain/file.abc" download="filename.123">
My routine clicks on a form button that already has a post and returns the file download.

Thanks

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Change download folder and file name on chromedriver

Post by Grovkillen » Fri Apr 02, 2021 4:30 am

Then you can add the download attribute to have it renamed to whatever you filename you want.

Changing the download path will not help you with the problem of slow and interrupted downloads.

I suggest you add some check within your script which look for a new file, and it is still not a fully downloaded file wait/loop back and do another check. If it falls X number of times you take care of that in a new routine. If the check is ok you carry on.
Let>ME=%Script%

Running: 15.0.27
version history

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Change download folder and file name on chromedriver

Post by thiagunix » Fri Apr 02, 2021 4:13 pm

The routine is on a remote computer and when I need to make any adjustments I access the remote desktop and make the adjustments.

I realized that the download is only performed when I have the remote desktop open. When I close the remote the routine continues to be executed but the file is not downloaded.

How my routine works:
I have a master routine that includes subroutines.

Code: Select all

Let>CHROMEDRIVER_EXE=C:\chromedriver\chromedriver.exe
ChromeStart>Chrome

// CHECK IF YOU HAVE SOMETHING TO BE IMPORTED
Include>%SCRIPT_DIR%\collect.scp
// PO_TOTAL VARIABLE CREATED IN COLLECT.SCP WITH THE RESULT OF THE IMPORT CONSULTATION
Wait>2
IF>(PO_TOTAL <> 0) AND (PO_TOTAL <> )
  // LOG IN TO THE SUPPLIER SYSTEM OF THE FILE TO BE IMPORTED
  Include>%SCRIPT_DIR%\LOGIN.scp

   // IF THERE IS STILL A FILE TO BE IMPORTED
  While>PO_TOTAL>0

   // DOWNLOAD SUPPLIER FILE
   Include>%SCRIPT_DIR%\down_supplier.scp

   // MOVE THE DOWNLOAD FOLDER FILE TO THE IMPORT LOCATION 
   Include>%SCRIPT_DIR%\MOVE_FILE.scp

   //IMPORTS THE FILE TO THE LOCAL SYSTEM
   Include>%SCRIPT_DIR%\IMPORT_FILE.scp

// CHECK IF THERE IS ANY MORE FILES TO BE COLLECTED FROM THE SUPPLIER 
   include>%SCRIPT_DIR%\collect.scp
  ENDWHILE
ENDIF
Include>%SCRIPT_DIR%\LOGOUT.scp
ChromeQuit>Chrome
At the end of each collection at the supplier, he registers the name of the download file in the bank.
The problem is that the file is not being downloaded when the remote desktop is closed.
Now be in doubt what to do.

Thanks

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Change download folder and file name on chromedriver

Post by Dorian (MJT support) » Fri Apr 02, 2021 4:47 pm

Yes, we have a Custom Scripting Service. Message me or go here

thiagunix
Junior Coder
Posts: 23
Joined: Tue May 05, 2020 2:16 pm

Re: Change download folder and file name on chromedriver

Post by thiagunix » Fri Apr 02, 2021 6:11 pm

It makes perfect sense for my problem.

Strange that this routine has been running for over 1 year and started to present this problem a few weeks ago.

Is there any configuration to fix this problem with Winsta0?

Thanks

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Change download folder and file name on chromedriver

Post by Grovkillen » Fri Apr 02, 2021 8:53 pm

This is one of the reasons I turned to Teamviewer. Price is fair and the service is great.
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts