Unable to upload file

I have tried everything in uploading file using katalon studio. some times it shows unable to focus on element and sometime test passes but file never gets uploaded.
i have used Uploadfile function and used ‘delay’, ‘Wait For Element Attribute Value’ prior to uploadfile so that page can properly load completely.
Even for the below mentioned website it is not uploading, following is my script;

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.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.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 internal.GlobalVariable as GlobalVariable

WebUI.openBrowser(‘https://www.convert-jpg-to-pdf.net/’)
WebUI.waitForPageLoad(3)
WebUI.delay(2)
WebUI.waitForElementAttributeValue(findTestObject(‘btnup’), ‘class’, ‘btn btn-primary’, 5)
WebUI.delay(2)
WebUI.uploadFile(findTestObject(‘btnup’), ‘D:\\ss.JPG’)
WebUI.waitForPageLoad(3)

Attribute used for uploadFile method is (input[type=‘file’]xpath,filePath,flowControl).So make sure that webElement which you have taken its input type is file or not.Otherwise file will not be uploaded.

Thanks so much, it is working for those which have Type ‘file’ :slight_smile:
May i know when can we have this restriction removed in Katalon studio so that we can upload file on the basis of other attributes like id, class or xpath?

if input type is not a file, what is the other solution ? because when I click the drag&drop field, window has opened but I couldn’t handle that one with using kalaton?

1 Like

The element used to upload a file is always an input type=file element. If that page seems to do something else (i.e. seems to use a different type of input element) understand it’s using smoke and mirrors to obfuscate its processes.

Knowing that, it becomes a problem of finding the real type=file element, because it’s there somewhere.

In the developer tools console, type this:

document.querySelectorAll("input[type=file]")

When I did that, I received a single element with an id. On a second page invocation, I received a different id proving the id is dynamic. That means the id isn’t much help for testing BUT knowing that it exists and the CSS can find it proves we can use the same CSS to find the type=file input element and use it in your test.

So, stop using the Test Object “btnup” and build your own “betterBtnUp”. Put the same CSS in the CSS properties for the test object:

input[type=file]

then try

WebUI.uploadFile(findTestObject(‘betterBtnup’), ‘D:\\ss.JPG’)
3 Likes

Thanks Russ for guiding me on this. How about if i have to upload file when i cannot view file type. Please see the attachment, what can be done in this case to upload file. Just to add here, clicking on this filed works both ways to drag and drop and also opens a browser pop up to select files from drive.

My understanding is that the drag/drop APIs should be used for something like this. But I have never used them so I’d be the wrong person to ask and advise you.

Having said that, I don’t see how to drag a file from outside the browser onto a page. There are some pretty smart people around here though, maybe a few of them have solved this scenario.

@Marek_Melocik? @Mate_Mrse? @kazurayam? Anyone?

Just guessing - can you look around this div element? There may be some hidden input.

hi…i am a beginner to automation trying to figure out the upload file using katalon studio. I have tried uploading on the mentioned website, nothing is getting uploaded (given my script below). Can someone help me with it.

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.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.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 internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://www.convert-jpg-to-pdf.net/’)

WebUI.click(findTestObject(‘Object Repository/Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button’))

WebUI.delay(2)

WebUI.waitForElementAttributeValue(findTestObject(‘Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button’),

‘class’, ‘btn btn-primary’, 5)

WebUI.delay(2)

WebUI.uploadFile(findTestObject(‘Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button’),

‘/Users/swapnaputta/Downloads/seasonal-wallpaper-1.jpg’)

WebUI.waitForPageLoad(3)

WebUI.click(findTestObject(‘Object Repository/Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_convert_to_pdf_button’))

WebUI.click(findTestObject(‘Object Repository/Page_Your converted PDF document/a_Download your PDF’))

WebUI.closeBrowser()

Maybe try switching forward slashes and back slashes?

Do you get any error messages?

Tried by changing the slashes. When i run the test case it will execute till the upload selection and a window opens to select the file and then it stops there.

Still receiving the error

SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See SLF4J Error Codes for further details.
2019-08-20 09:09:15.437 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-08-20 09:09:15.440 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/up
2019-08-20 09:09:16.110 DEBUG testcase.up - 1: openBrowser(“”)
2019-08-20 09:09:16.695 INFO c.k.k.core.webui.driver.DriverFactory - Starting ‘Chrome’ driver
Aug 20, 2019 9:09:16 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using new ChromeOptions() is preferred to DesiredCapabilities.chrome()
2019-08-20 09:09:16.752 INFO c.k.k.core.webui.driver.DriverFactory - Action delay is set to 0 seconds
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864}) on port 47905
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Aug 20, 2019 9:09:19 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2019-08-20 09:09:19.599 INFO c.k.k.core.webui.driver.DriverFactory - sessionId = b3b69435786f45e0286f2f4c0243a029
2019-08-20 09:09:19.641 INFO c.k.k.core.webui.driver.DriverFactory - browser = Chrome 76.0.3809.100
2019-08-20 09:09:19.642 INFO c.k.k.core.webui.driver.DriverFactory - platform = Mac OS X
2019-08-20 09:09:19.654 INFO c.k.k.core.webui.driver.DriverFactory - seleniumVersion = 3.141.59
2019-08-20 09:09:19.657 INFO c.k.k.core.webui.driver.DriverFactory - proxyInformation = ProxyInformation{proxyOption=NO_PROXY, proxyServerType=HTTP, password=, proxyServerAddress=, proxyServerPort=0}
2019-08-20 09:09:19.667 DEBUG testcase.up - 2: navigateToUrl(“https://www.convert-jpg-to-pdf.net/”)
2019-08-20 09:09:23.043 DEBUG testcase.up - 3: click(findTestObject(“Object Repository/Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button”))
2019-08-20 09:09:23.460 DEBUG testcase.up - 4: delay(2)
2019-08-20 09:09:25.563 DEBUG testcase.up - 5: waitForElementAttributeValue(findTestObject(“Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button”), “class”, “btn btn-primary”, 5)
2019-08-20 09:09:25.754 DEBUG testcase.up - 6: delay(2)
2019-08-20 09:09:27.775 DEBUG testcase.up - 7: uploadFile(findTestObject(“Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button”), “\Users\swapnaputta\Downloads\seasonal-wallpaper-1.jpg”)
2019-08-20 09:09:28.160 DEBUG testcase.up - 8: FilePath = getAttribute(findTestObject(“Page_Convert JPG to PDF for free - JPG to PDF online converter/input_JPG to convert to PDF_select_file_button”), “\Users\swapnaputta\Downloads\seasonal-wallpaper-1.jpg”)
2019-08-20 09:09:28.274 DEBUG testcase.up - 9: verifyMatch(FilePath, “\Users\swapnaputta\Download\seasonal-wallpaper-1.jpg”, false)
2019-08-20 09:09:28.313 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to verify match between actual text ‘null’ and expected text ‘\Users\swapnaputta\Download\seasonal-wallpaper-1.jpg’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘null’ and expected text ‘\Users\swapnaputta\Download\seasonal-wallpaper-1.jpg’ are not matched
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword$_verifyMatch_closure1.doCall(VerifyMatchKeyword.groovy:57)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword$_verifyMatch_closure1.call(VerifyMatchKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword.verifyMatch(VerifyMatchKeyword.groovy:60)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword.execute(VerifyMatchKeyword.groovy:45)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.keyword.BuiltinKeywords.verifyMatch(BuiltinKeywords.groovy:73)
at up.run(up:36)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1566272350486.run(TempTestCase1566272350486.groovy:21)
)
2019-08-20 09:09:28.339 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/up FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Actual text ‘null’ and expected text ‘\Users\swapnaputta\Download\seasonal-wallpaper-1.jpg’ are not matched
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword$_verifyMatch_closure1.doCall(VerifyMatchKeyword.groovy:57)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword$_verifyMatch_closure1.call(VerifyMatchKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword.verifyMatch(VerifyMatchKeyword.groovy:60)
at com.kms.katalon.core.keyword.builtin.VerifyMatchKeyword.execute(VerifyMatchKeyword.groovy:45)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.keyword.BuiltinKeywords.verifyMatch(BuiltinKeywords.groovy:73)
at up.run(up:36)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1566272350486.run(TempTestCase1566272350486.groovy:21)

2019-08-20 09:09:28.366 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/up

Hello, could you please help me with script for selecting and uploading files? We are just starting our automation journey with Katalon. Thank you very much in advance.

Katalon Studio version 6.2.1
Script: https://share.getcloudapp.com/7Ku2rP5O
Error:
Reason:
org.openqa.selenium.UnsupportedCommandException: POST /session/14bad2d6-5b65-403c-9fb5-f9556efd9311/file did not match a known command
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘TOSHCHEVA’, ip: ‘10.0.2.141’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 69.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20190827005903, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 14736, moz:profile: C:\Users\daria.toshcheva\Ap…, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 14bad2d6-5b65-403c-9fb5-f9556efd9311
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CFirefoxDriver.execute(CFirefoxDriver.java:28)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.upload(RemoteWebElement.java:116)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:102)
at Import Translation Memory.run(Import Translation Memory:51)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1568296055299.run(TempTestCase1568296055299.groovy:21)