Need Help Automating File Upload Without Input Tag

Hi Team,

I’m facing an issue while automating a file upload scenario. Th


e web application I’m testing does not support the <input> tag for the upload button.

Is there any alternative approach to automate this? I’d appreciate any suggestions.

Thanks!

Hi,

You could use PyAutoGui

Or a library like ImageHorizonLibrary

Regards
Charlie

Hi, are you sure there is no hidden inupt field activated afer the click on “upload” button? Maybe the solution would be to disable native win window. Thread below delivers solution. For browser(PW) library you just need to use Execute Javascript, but works alos for Se.

And

Trying the same with PyAutoGui
Seeing “Importing test library ‘PyAutoGUI’ failed: ModuleNotFoundError: No module named ‘PyAutoGUI’”
I have installed and imported the PyAutoGui library in the testcase. Please let me know if i have missed anything
MouseInfo 0.1.3
pillow 10.2.0
pip 20.2.1
PyAutoGUI 0.9.54
pycparser 2.20
PyGetWindow 0.0.9
PyMsgBox 1.0.9
PyNaCl 1.5.0
pyperclip 1.9.0
PyRect 0.2.0
PyScreeze 1.0.1
PySocks 1.7.1
python3-xlib 0.15
pytweening 1.2.0
robotframework 6.1.1
robotframework-pythonlibcore 2.1.0
robotframework-seleniumlibrary 4.5.0
selenium 3.141.0
setuptools 49.2.1
six 1.15.0
urllib3 1.25.11

Probably the library import is wrong.
Search for examples of use.
Try:

Library    pyautogui

About the original problem. There must exist an input tag somewhere.

Some cases, specifically those where user is expected to “drop and drop” the file do not have a specified input tag for fileupload.

SeleniumTestability does have keyword that does following:

  • create hidden input field into a form at the time keyword is called.
  • “uploads the file” into form
  • Simulates the drag and drop event so that the frontend code can work similarry as user would have dragged the file from operating system into the browser element that handles incoming drop and drop event…
  • removes the hidden input field.

With the caveat that ST probably is not fully working, maybe try it it … Or copy the relevant parts off?

JS part of the code here: robotframework-seleniumtestability/src/SeleniumTestability/javascript.py at master · MarketSquare/robotframework-seleniumtestability · GitHub

And keyword Drag and Drop is overwritten here; robotframework-seleniumtestability/src/SeleniumTestability/plugin.py at master · MarketSquare/robotframework-seleniumtestability · GitHub … Keyword works in a way that if extra kwarg html5 is True and source element is: file://some/path/to/file.txt, above javascript code is executed and does the steps described above.

1 Like

Not a hard requirement, sadly :slight_smile: Any element can have event listeners to accept drag and drop events that can then be used to upload a file to backend. One notable js framework that does this; https://www.dropzone.dev/

1 Like

After debugging the PyAutoGUI error, I found that the package was not installing in the virtual environment but instead in ~/.local/lib/python3.8/site-packages, which caused the issue. And i dont have the permission to install the PyAutoGUI in virtual env

what would be the best solution to fix this and proceed with PyAutoGUI, or using JavaScript instead?

OK, I was still in the world of HTML :slight_smile:

1 Like

Hi Madhurya,

I’d suggest poking around the html source with devtools and also check the network tab of devtools, find the call when the file is being uploaded and try to figure out how the page actually uploads the file.

If there’s no file <input>, then it’s most likely being done with Javascript, so if you can figure out which JS function, then hopefully you can call it with Execute Javascript or Evaluate JavaScript (depending which library you’re using.

I’ll note a hidden file input is the most common approach, I’ve only seen 1 application that did file uploads with pure Javascript and no file input, but once you know how the page does it in the browser, you’re 1/2 way to figuring out how to automate it.

Dave.

2 Likes

Thank you everyone for all the suggestions, will try to understand the upload function and give it a try

1 Like