How to Resolve File Upload Issues


#1

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:

image

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:

WebUI.sendKeys(findTestObject("path/to/object"), "path/to/file")

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!


Is there a way to findTestObject by id?
Is it possible to upload data like this?
#2


I created an object in my object repository but now I am confused on how to use the ('path/to/object')
Is it literally //input[@='txtFileURL'] ? Or is it something else, do I still need to go findTestObject('Object Repository/Website/_path/to/object_') ?


#3

Something like this…

You can leave off “Object Repository” since it’s “known”. All you need to provide is the rest - which should match your OR layout.


#4

The ‘path/to/object’ is the location of your test object in the object repository. For instance, if I had a test object here:

image

Then I would use:

findTestObject('Object Repository/folder1/folder2/myTestObject')

or, as Russ mentioned, since we’re calling the “findTestObject()” method, it actually already knows that we’re looking in the object repository, so you can leave that part off if you’d like:

findTestObject('folder1/folder2/myTestObject')


#5

I kept putting the object in the wrong repository. I finally found it, thank you so much for the tips and help!