File Explorer automation

I need to automate uploading a document from File explorer. Opened while in chrome…

How would I focus this application and select one of the text files?

Hello,

If your page / DOM in Chrome contains an input that you can use as xpath, it would be easier to use SeleniumLibrary Choose File keyword :

Choose File    //input[@type='file']    c:\user\documents\testBlanketPo.txt

This targets the input and loads directly the file into browser.
It would avoid installing additional libraries to interact with the operating system windows, and ease the functioning and portability of your script if using another OS.

Regards.
Charlie

2 Likes

image
Here’s the page I am uploading to and the pop-up file explorer above is what I have access to for now.

I can talk to a dev but would probably take a while for that change.

Any other suggestions will be greatly appreciated!

Hi,

Not sure any modification is needed.
Just check/inspect the Dom content, see if the area to upload has an input with @class, @type or else.

Goal is just to target the entry point to load the file.

Regards

2 Likes

Few observations;

Drag and Drop from outside of of the browser Into DOM element will be Very Painful to Not Possible.

What @CharlieScene said, Choose file in selenium context is just fine, you do not need to interact with explorer itself, you just need to know the filename and full path and provide that to

HOWEVER Depending on how the file upload is implemented on the page, using vanilla “Choose File” keyword wont help either. Reason; Some developers opt out to implement file selecting the native ui dialog, eg, the only way to upload a file for the user is to explicitly drag and drop the file from outside the browser into the form. That can be worked around with by creating a temporary file input to the form, then using Choose file to upload it to that temporary element and once that’s done, Execute Javascript can be used to create artificial drag and drop event. Example library that implements this;

robotframework-seleniumtestability/src/SeleniumTestability/plugin.py at master · MarketSquare/robotframework-seleniumtestability · GitHub && robotframework-seleniumtestability/src/SeleniumTestability/javascript.py at master · MarketSquare/robotframework-seleniumtestability · GitHub

But still Choose File is the most straight forward thing …

2 Likes


Only problem is it’s sort of a hidden child element (screenshot above)

image

RF error:

I initially had it Focus Application - for the File Explorer, click on the txt file and click Open
but that Library wouldn’t work for headless automation. I will try the links you suggested, thank you :slight_smile: