I’ve been seeing several topics around issues with uploading files to a web application when using the WebUI.uploadFile() method, so I thought I’d share the best alternative approach (note: this is the same approach that one would take in Selenium as well):
Step 1: Identify the file upload field
Lets take a typical file upload field:
What we want is the
<input> element for the field, which will look something like this (with probably a bunch of other attributes):
<input type="file" id="someId">
once you find it…
Step 2: Create a Test Object
Create a Test Object to locate the element:
Step 3: Use the WebUI.sendKeys() method to upload the file
Instead of using WebUI.uploadFile(), use this:
You will need to replace the “path/to/object” with the path to the Test Object created in Step 2, and replace “path/to/file” with the path to the file you want to upload.
Bonus Step: Multiple files upload
If you need to upload multiple files at once, build a String that combines your paths, delimited by a new line character:
String path1 = "path/to/first/file" String path2 = "path/to/second/file" String finalPath = path1 + "\n" + path2 WebUI.sendKeys(findTestObject("path/to/object"), finalPath)
Hope this can help. Good luck in your automation efforts!