WebUI.uploadFiles causing an error and I don't know why

Hi guys,

So there are a lot of resources available for uploading files and I have tried so hard. The last help I recieved led me to the script below. However I attached a screenshot of the error. To my understanding this is due to the Object not being recognised properly. I have tried editting the xpath by replacing the “*” with "“input”, by removing it entirely and just having //[id@“FileInput”], but no luck.

I have additionally added a screenshot of the HTML of the Choose Files. Where my curser is relates to the button <input … >

Please can someone help with the object that it needs to use. I tried WebUI.sendKeys but that did nothing.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

import com.kms.katalon.core.testobject.ConditionType as ConditionType

email = "OTPTesting16@gmail.com"

WebUI.openBrowser('')

WebUI.navigateToUrl('https://inscape-connect-staging.stratusolvecloud.com/UserManagement/login/')

WebUI.setText(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/input_Login to_c1'), 
    email)

WebUI.setEncryptedText(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/input_Login to_c2'), 
    'p4y+y39Ir5PEPmX20UxFKw==')

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/button_Login'))

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - ApplicationAccess/div_Continue'))

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/button_Upload'))

xpath = '//*input[@id="FileInput"]'
TestObject uploadButton = new TestObject(xpath)
uploadButton.addProperty("xpath", ConditionType.EQUALS, xpath)

WebUI.uploadFile(uploadButton, "C:\\Users\\tomgb\\Pictures\\random\\random.jpg")



Try…

String css = '#FileInput'
TestObject uploadButton = new TestObject() 
uploadButton.addProperty("css", ConditionType.EQUALS, css)

That is also isn’t working. Do I need to copy ‘#FileInput’ exactly as you put it?

Is there different types of upload buttons? I am starting to think that maybe that’s the problem.

This is the exact Web Element:
<input name="FileInput[]" id="FileInput" class="FileInput" type="file" multiple="multiple" accept="image/*;capture=camera">

in HTML in CSS
id="FileInput" #FileInput
class="my-class" .my-class
<div> div
<span> span
<input> input
<input type="text"> input[type=text]
<input type="file"> input[type=file]
<div class="my-class"> div.my-class
etc.

As to the problem, are you certain that the element is available when your test case tries to access it?

Is it by chance inside an iframe?

Yeah when I test case opens the modal, it should be able to click the button.

May I ask what an iframe is? This is a model that pops up, and then you click on this button.

The steps are that

  1. you load on a page
  2. click upload
  3. model pops up with the button “choose files”

Search back (up) in the HTML for…

<iframe src="..." ...>

If your button is inside an iframe, that is your problem:

Ahh thank you! I hope it’s that then. In the screenshot you posted, would I place the xpath of the iframe in that space?

Caveat/confession: I don’t use conventional Test Objects, so my knowledge here is “weak”.

I believe you must create a test object first for the iframe.

Then, in your settings for the input file button, click Browse and select the iframe test object.

I also noticed that you have an incorrect xpath in your post above. You have:
//*input[@id="FileInput"] // both asterisk and the tag name

However, it should be starting with asterisk:
//*[@id="FileInput"]

or starting with tag name:

//input[@id="FileInput"]

or a format only for the id tag:

id("FileInput")

Copy and paste each of these separately into your DevTools screen (after hitting CTRL + F ) and checking if you get a “1 of 1” to the right of the xpath.

1 Like

Hi there. Yeah I also spotted this afterwards, however these screenshots were specifically for the question, it was failing in all instances and so I just set this up for the sake of the question. I was struggling all day with this

I agree with @grylion54 here, it looks like your xpath syntax is the problem, so easy fix. If it still doesn’t work after that, consider my guide on how to resolve actual upload problems:

How to Resolve File Upload Issues

But as stated, I think if you fix your xpath you should be good. If you fix the xpath but still get an error, please share that error. The one you’ve provided is simply due to that xpath being incorrect.

@Russ_Thomas, @Brandon_Hein, @grylion54

So just to close the loop, I got it working now. I attached two screenshots and my code
The first screenshot, is the iframe object. I used Spy Web to capture the iframe of the window.
The second screenshot shows the xpath of the Choose Files button, linking it to the parent iframe.

Is there a place on this forum for me to step by step go through what I did with all your help to help others?

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

import com.kms.katalon.core.testobject.ConditionType as ConditionType

email = "OTPTesting17@gmail.com"

WebUI.openBrowser('')

WebUI.navigateToUrl('https://inscape-connect-staging.stratusolvecloud.com/UserManagement/login/')

WebUI.setText(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/input_Login to_c1'), 
    email)

WebUI.setEncryptedText(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/input_Login to_c2'), 
    'p4y+y39Ir5PEPmX20UxFKw==')

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Inscape Connect - Account Management/button_Login'))

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - ApplicationAccess/div_Continue'))

WebUI.click(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/button_Upload'))

//xpath = '//*[@id="FileInput"]'
//TestObject uploadButton = new TestObject(xpath)
//uploadButton.addProperty("xpath", ConditionType.EQUALS, xpath)

//WebUI.uploadFile(uploadButton, "C:\\Users\\tomgb\\Pictures\\random\\random.png")

WebUI.uploadFile(findTestObject('Object Repository/File_Upload/Page_Connect - Operations - Student Enrolment/choose_files'), 'C:\\Users\\tomgb\\OneDrive\\Pictures\\3D image 1.jpg')


2 Likes

Hi @thomas.bates, thank you so much for your confirmation. We would appreciate if you could mark a solution for the answer of your concern. If possible, please summarize the answer if you collect from different supporters in one thread and mark it as solution. The system will ONLY record one solution for each post. Hope this helps and please let me know if you need further assistance.

P/s: please check how to mark a solution here.