Upload File By Selector usage without input type=file

I have a problem with uploading a file via Upload File By Selector. It seems to require tag with type=file, but the recent target of my testing is not using it anymore. And there are no hidden input tags on the page. It seems that Selenium works the same way.

My question here is: is there a workaround and/or plans to support type=button type of file upload? If I use Python, I can’t send the browser object as parameter there since I have opened the UI page already.

Hi Esa,

You’ll need to do some digging in the browser’s dev tools to find out how the site uploads the file.

The standard way is there will be a form input field of type=”file” somewhere on the page, often it’s hidden and the page element you interact with uses some javascript to select the file and update the hidden input field, if that’s the case find the input field and it’s ID and use that with `Upload File By Selector`

If there is really no input field of type=”file” anywhere, then

  • First go give the developer a hard time for using non-standard code, make the dev a nice embarrassing “I cost the company money unnecessarily“ “award“ or something, you want to make sure the whole dev team sees them getting “acknowledged“ for doing something non-standard (bad) and costing the company money by making testing harder (this will discourage the other devs from doing something similar)
  • Next you’ll need to check the code to see how it’s actually uploading the file, as it’s a custom solution we can’t tell you and the dev should be able to tell you what they did. If your really lucky there’ll be a javascript function on the page you can call with the file path as an argument, if so use Evaluate JavaScript to trigger it

I think that you can use the keyword Promise To Upload File for this.

Thanks for the reply!
I already used the step one, so it’s time to negotiate with the developer who likes to use the latest, not-yet-covered-by-any-keywords UI enhancements.

I don’t see how this would solve my problem, but thank you for the suggestion.

That keyword seems to mimic this Playwright class FileChooser | Playwright

Thanks, I will look into it.
Anyway, I got the problem solved as the appeared in the source. I only have to click the button to open the file directory, use upload by selector. Maybe there is a way to open it in invisible mode or in the background - or at least to close it, but it really doesn’t matter in my case.

1 Like