Uploading a File

Hello,
I am attempting to following the directions at this website to upload a file, but am not having success. Any help is appreciated…
An object on my website has type = “file” as the website specifies:

<input id="ABC" class"foggy w250px" name="ABC" type="file">

When I click run Katalon generates an alert popup error message with an exclamation mark but with not text. I click OK and the script runs.

If I attempt the following…

WebUI.uploadFile(findTestObject('Upload File'), 'C:\\etc\\filename.xml')

… then I get the following error message…

Test object with id ‘Object Repository/Upload File’ does not exist

Finding Test Object with id ‘Object Repository/Upload File’

Test object with id ‘Object Repository/’ does not exist

Finding Test Object with id ‘Object Repository/’

Checking object

Unable to upload file ‘C:\etc\filename.xml’ to object (Root cause: java.lang.IllegalArgumentException: Object is null)

2 Likes

Make sure that your local file exists in this location - C:\etc\filename.xml

Marek Melocik said:

Make sure that your local file exists in this location - C:\etc\filename.xml

Thanks.
I confirmed that it exists.
I also tried the following:

WebUI.sendKeys(findTestObject('Upload File'), 'C:\etc\filename.xml')

It gives me…

Start action : sendKeys

Test object with id ‘Object Repository/Upload File’ does not exist

Finding Test Object with id ‘Object Repository/Upload File’

Finding Test Object with id ‘Object Repository/’

Sending keys ‘C:\etc\filename.xml’ to object: ‘tempBody’

Checking timeout

Test object with id ‘Object Repository/’ does not exist

Finding web element with id: ‘tempBody’ located by ‘By.cssSelector: body’ in ‘30’ second(s)

Found 1 web elements with id: ‘tempBody’ located by ‘By.cssSelector: body’ in ‘30’ second(s)

Keys ‘C:\etc\filename.xml’ sent to object: ‘tempBody’

End action : sendKeys

Test Cases/Imported from Selenium IDE Scripts/SGN

End Test Case : Test Cases/Imported from Selenium IDE Scripts/SGN

But nothing is selected

Hello,

I noticed this error in your log:

Test object with id 'Object Repository/Upload File' does not exist

Make sure that your path to test object is correct and if object exists.

Also, you are looking for some blank object in your script:

Test object with id 'Object Repository/' does not exist

Use auto it for uploading a file

What browser are you using? I had lot if issues when I was using IE for upload file finally found solution use auto it with katalon for upload file.

mahesh joshi said:

Use auto it for uploading a file

What do you mean?

This will help see the video https://www.youtube.com/watch?v=OvrYrbNHDcw

Ilya Novak said:

Hello,
I am attempting to following the directions at this website to upload a file, but am not having success. Any help is appreciated…
An object on my website has type = “file” as the website specifies:

<input id="ABC" class"foggy w250px" name="ABC" type="file">

When I click run Katalon generates an alert popup error message with an exclamation mark but with not text. I click OK and the script runs.

If I attempt the following…

WebUI.uploadFile(findTestObject('Upload File'), 'C:\\etc\\filename.xml')

… then I get the following error message…

Test object with id ‘Object Repository/Upload File’ does not exist

Finding Test Object with id ‘Object Repository/Upload File’

Test object with id ‘Object Repository/’ does not exist

Finding Test Object with id ‘Object Repository/’

Checking object

Unable to upload file ‘C:\etc\filename.xml’ to object (Root cause: java.lang.IllegalArgumentException: Object is null)

you can use the following keyword to upload a file:

for more details: https://www.katalon.com/resources-center/tutorials/handle-file-uploads/

WebUI.uploadFile(findTestObject('Upload File'), 'C:\\\\Users\\\\Public\\\\Pictures\\\\Sample Pictures\\\\Desert.jpg') 

mahesh joshi said:

This will help see the video https://www.youtube.com/watch?v=OvrYrbNHDcw

Similar way we can execute .vbs files also.

try this https://stackoverflow.com/questions/45398100/how-to-upload-a-file-photo-using-katalon-studio

Try new katalon plugin :smiley: with robo uploading work so great

Blockquote
import com.kms.katalon.keyword.uploadfile.UploadFile

CustomKeywords.‘com.kms.katalon.keyword.uploadfile.UploadFile.uploadFileUsingRobot’(findTestObject(‘Object Repository/Folder/Object’), ‘D:\Windows\Desktop\file.png’)

if using dynamic object :

CustomKeywords.‘com.kms.katalon.keyword.uploadfile.UploadFile.uploadFileUsingRobot’(object name), ‘D:\Windows\Desktop\file.png’)

Can you write here, step by step to do it?

  1. First, create a keyword to the file upload button or link, something like: “Object Repository/Page_Add_Document_To_Current_Account/lnk_choose_a_file”

  2. Next, create a method call for which will handle the upload, like
    class uploadNewFile {
    /**

    • This method will be used to upload file
      */
      @Keyword
      def uploadFileToTest(TestObject to, String filePath){
      WebUI.click(to)
      WebUI.delay(3) //i’d recommend adding this delay to give the code time to run
      StringSelection ss = new StringSelection(filePath)
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null)
      WebUI.delay(2) //same reason as above

      Robot robot = new Robot()
      robot.keyPress(KeyEvent.VK_ENTER)
      robot.keyRelease(KeyEvent.VK_ENTER);
      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
      }
      }

  3. Next, call the method where it needs to be in your code and it will appear something like:
    CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(null), ‘’)

  4. Next, replace null in 3 above with the keyword you created in 1 above, then insert the filepath of the file to be uploaded into the ‘’ in 3 above.

UPDATE:
//KS seems to have an issue with selecting the correct path to the file, so the best solution, for me, was to include the desired docs to be added into the Data Files container in KS, then call it from there. This ensures that the same doc is called, no matter who or where the test is being run from

WebUI.delay(2)

//this string will replace the user/system path being used to run the test at any particular time
String textDir = RunConfiguration.getProjectDir()

//the default path connectors were failing in the tests, so, it was necessary to replace them, which worked for me
String replaced = textDir.replace(’/’, ‘\’)
//_please note that the single backslash in code above should be double, as in \ \ , but when entered into the comments here, it’s represented as a single backslash. Not sure why this is the case… _

  1. The final statement would be something like:
    CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(‘Object Repository/Page_Add_Document_To_Current_Account/lnk_choose_a_file’),
    replaced + ‘\Data Files\name-of-file.txt/png/doc/etc’)
    //_please note that the single backslash before and after Data Files, and for all paths to the file to be uploaded, should be double, as in \ \ , but when entered into the comments here, it’s represented as a single backslash. Not sure why this is the case… _
    All the best
1 Like

Well, thank you, Sir.

Even I am having similar problem. Am not able to upload the file even thought it clicks on an object but doesn’t enter the path not uploading document.

I tried also this way but it doesn’t like file name after filepath and where filename starts and my file name is blankpage.pdf.
CustomKeywords.‘methodCalls.uploadNewFile.uploadFileToTest’(findTestObject(‘objectname’), ‘D:/Sample Document/blankpage.pdf’)
expecting ‘)’, found ‘blankpage’ @ line 55, column 111

Hi all,

I’ve amended my test to include a better option of navigating to the desired file to be uploaded.

Regards,
A

I didn’t get this part of you update.
//KS seems to have an issue with selecting the correct path to the file, so the best solution, for me, was to include the desired docs to be added into the Data Files container in KS, then call it from there. This ensures that the same doc is called, no matter who or where the test is being run from.
Please provide in detail how to add desired docs into the Data Files as I can only add excel or csv filed in Data Files.

@paresh.soni, simply right-click on the desired folder in Data Files and select the option to Open containing folder.

Add the required file here and when you follow the steps I outlined above, you should be able to reach the file and upload it