Uploading a file from your local machine to your website is a pretty common scenario. It's an important scenario that needs to be tested and it usually completes the test flow. 

The problem you might face in your attempt to upload a file is when you click on the upload button. It immediately opens the native OS file explorer dialog, where you are required to select the file that you want to upload. Selenium cannot automate the native OS file dialog, so you won't be able to record your actions on that dialog.

Let's have a look at this input element of type file:

As mentioned above, clicking on the "Choose File" button would trigger the native OS file explorer dialog:

This element can also be wrapped by another element with different styles, but as long as it's an input element of type file, this following addon will know how to handle it.

The File Uploader Addon

To overcome this limitation and to simplify the file upload process, we've created the File Uploader addon. This addon contains two actions for uploading a file in your web test:

Upload File using XPath - This is an action that requires the XPath of the input element: //input[@type = 'file']. The second parameter is of course, the local path to the file you want to upload.


Upload file to input element - This is an element action and you need to use it on the input element. It works on two types of elements that are located by these XPaths: //button[text()='Upload'] AND //input[@type = 'file']. This element action takes only one input parameter which is the local path to the file that you want to upload.

Important Note:

Some websites require an action to happen before the file type element becomes visible in the explorer, If your element is missing try to continue the sequence of uploading the file (manually) until you can detect the element try to do it step by step.

Still need help?

Common issues and troubleshoot / missing elements:

https://forum.testproject.io/t/file-uploading-addon-fails-during-runtime-to-upload-file/2479

https://forum.testproject.io/t/issue-with-file-upload-button/4599/19

Feel free to reach out to us at any time in the Chat or Forum. Or explore more in our official Documentation 😉🎓

Did this answer your question?