[WebUI] Upload File

thank you it really helped me

Hi, I used the keyword for uploading the file as well, and I do get an error : Caused by: org.openqa.selenium.ElementNotInteractableException: element not interactable

I am not a coder, I would like to know how I could resolve the problem without using skrip. Do someone does have a solution?

I have problem with the same relation path, the test case not able to run in Windows and Linux with the same path.

So the solution here:

import java.nio.file.Path as Path
import java.nio.file.Paths as Paths

String filePath = RunConfiguration.getProjectDir() + '/Data Files/test-doc.pdf'

Path absolutePath = Paths.get(filePath)

String absolutePathStr = absolutePath.toString()

WebUI.uploadFile(findTestObject('object'), absolutePathStr)

hi adamspam, I have same issue. Tests run locally uploading a file from a path, but cannot get to run in GitLab. Did you ever find a solution ?

You should take alook at @vu.bui’s solution:

Thanks duyluong for quick reply and vu.bui, trying out that solution and will let you know if it works

solution. adjusted slightly the code vu.bui posted and it worked for me. GitLab could not recognize the relative path, until I changed the Paths.get() to an array of the path (each folder, file name split out in the array.)

import com.kms.katalon.core.configuration.RunConfiguration
import java.nio.file.Path as Path
import java.nio.file.Paths as Paths

Path absolutePath = Paths.get(RunConfiguration.getProjectDir(), "Data Files", "test-doc.pdf");

String absolutePathStr = absolutePath.toString()

WebUI.uploadFile(findTestObject('object'), absolutePathStr)


Hey this code worked when we run in local but what if we run bitbucket Could you please help me

import java.nio.file.Path as Path
import java.nio.file.Paths as Paths

String filePath = RunConfiguration.getProjectDir() + '/Data Files/test-doc.pdf'

Path absolutePath = Paths.get(filePath)

String absolutePathStr = absolutePath.toString()

WebUI.uploadFile(findTestObject('object'), absolutePathStr)

You can try
Path absolutePath = Paths.get(RunConfiguration.getProjectDir(), “Data Files”, “test-doc.pdf”)

Hi @vpalmason

In this code String filePath = RunConfiguration.getProjectDir() + ‘/Data Files/test-doc.pdf’

Path absolutePath = Paths.get(filePath)

String absolutePathStr = absolutePath.toString()

WebUI.uploadFile(findTestObject(‘object’), absolutePathStr)

How you are clicking on browse button it seems that it is showing as uploading the file but without clicking on browse is this code works
Could you please respond asap

This is my code:
WebUI.click(findTestObject(‘Object Repository/FileUpload_Zephyr/Page_Test Repository - Zephyr Standalone 6.5/span_Browse’))


String userDir = System.getProperty(‘user.dir’)
String filePath = userDir + ‘/Documents/Testcases.xlsx’

WebUI.fileupload(findTestObject(‘Object Repository/FileUpload_Zephyr/Page_Test Repository - Zephyr Standalone 6.5/span_Browse’), filePath)

My code is also not working good please let me know for any corrections Thanks in advance

How can I Upload word or pdf file?

I’ve tried this and it works when the file is uploaded on the page. However, when I tried it to upload a photo, it did not display any error and the Test Case passed but the photo is not uploaded.
What could be wrong?

s there a way to upload without specifying a file name? I automated the file download, but I want to know the process of re-uploading the downloaded file after that.


I added Delay function and it works now

1 Like

Even if I want to specify a file name to upload, it is difficult to build an algorithm because the downloaded file name is not the same every time. Please help me.

to sum up

  1. Bring up the number of databases and download 2 files(not same file name)
  2. Reupload downloaded file (same page)

during the download process, is it possible to ‘rename’ the file and save it to a certain folder?
then you can have your own file name to be uploaded

1 Like

Can you tell me easily how to rename the downloaded file and put it in the designated folder from katalon? Video lectures related to this would be very beneficial.

I confirmed that It can be “rename” the file from the web browser…
But, When i record from katalon studio, " save as(rename) " can not be allowded.

I tried to make Custom Keyward like as

package renamefile

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 com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import org.openqa.selenium.WebElement
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper
import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException
import java.io.IOException
import java.util.Arrays
import org.apache.commons.io.comparator.LastModifiedFileComparator
import org.apache.commons.io.filefilter.WildcardFileFilter

public class filename {

public static void main(String[] args) throws IOException {

	FileRename fr= new FileRename()
	File newfile = fr.getTheNewestFile("C:\\Users\\hojun.lee\\Downloads", "csv")
	newfile.renameTo(new File("C:\\Users\\hojun.lee\\Downloads\\dd.csv"))
	String filename= newfile.getName()

	System.out.println("latest file is="+filename)

	FileRename fr1= new FileRename()
	File updated = fr1.getTheNewestFile("C:\\Users\\hojun.lee\\Downloads", "csv")
	System.out.println("Changed file name is ="+updated)

public File getTheNewestFile(String filePath, String ext) {
	File theNewestFile = null
	File dir = new File(filePath)
	FileFilter fileFilter = new WildcardFileFilter("*." + ext)
	File[] files = dir.listFiles(fileFilter)

	if (files.length > 0) {
		/** The newest file comes first **/
		Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE)
		theNewestFile = files[0]


But it does not work… "C:\Users\hojun.lee\Downloads " is download path that new file is downloaded on. i want to change new file to “dd.csv”.
Can you help me ?

Update as of Feb 2022, this keyword is working fine. Just make sure your test object is an input type=“file”. As an addition I put step to get current directory and combined it with file name to pass as parameters in the keyword.

** This keyword will not work on Jenkins, only on local machine.

Sample path : C:\BMMSEA\bigtix.testing\bigtix\Data Sources\

import com.kms.katalon.core.configuration.RunConfiguration

String path = RunConfiguration.getProjectDir() + “/Data Sources/”
path = path.replace(“/”, “\\”)

//Upload file - ID Proof
WebUI.uploadFile(findTestObject(‘Posv2/Sell Products/Patron and Mailing Info/Info to Collect/Btn_Upload ID Proof’, [‘index’: indexNo]), path + “Image.jpg”)