How to Drop and Drag files from windows explorer

I have an app that has a doc upload section. When I click in this area, windows explorer appears allowing me to grab a doc and upload it.

I cannot find any documentation on how to do this. the documentation i have found seems to only handle dropping and dragging within the same page.

Any help would be appreciated

Because you posted to the Web Testing area of the forum, I assume you’re talking about a web app/web page - not a Windows app.

File uploads are handled by a specific HTML element with a type set to “file”:

<input type="file" ...>

Essentially, even though it may not look like one, the input type=“file” element behaves as a button. It responds to clicks like any other button.

Use the browser DevTools to examine the HTML on the page. It will help you find the file upload input element.

1 Like

Give this a read:

tl;dr use WebUI.uploadFile() or WebUI.sendKeys() to the <input type=file> field that Russ mentioned.

1 Like

yes, i am on a webpage and a doc upload section appears after i choose a value from the drop down. once i click in that area, windows explorer appears for me to choose a file. i will try your suggestions now and report back

here is the page

and this is what i get when i click in that drop section

the problem i am having is not with the click. that works. the problem i am having is that when the windows explorer appears, katalon stops recording.

here is what the element looks like when i use f12

There’s only one way to say this - there aren’t many “experts” round here that use the record web feature.

In essence, what you need to do, is build Test Objects for the remainder of your test steps. Do this by hand. Nothing in your Object Repository is magical or mysterious - they’re the same Test Objects whether you built them or a recorder built them.

1 Like

As Russ said, you’ll need to create a test object by hand to handle this, the recorder is only a tool, not a full solution.

Your test object would be very simple, just an xpath like this:

//input[@type='file']

awesome. thank you. i will try this out and get back to you

OK guys, i really dont mean to be a pain in the ass and i am obviously not an expert here, but i tried what you said and that did not work.
here is what i see when i spy the object

i attempted to change the xpath to what you said and that did not work. it was not able to find the object with that. so i left the xpath the way you see it in the screenshot and got this error:
04-17-2020 09:38:21 AM sendKeys(findTestObject(“Object Repository/Page_Online Services/UploadSectionArea”), “C:\Documents\MyLicense 1 Test Plan1.doc”)

Elapsed time: 35.518s

Unable to send keys ‘C:\Documents\MyLicense 1 Test Plan1.doc’ to object ‘Object Repository/Page_Online Services/UploadSectionArea’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to send keys ‘C:\Documents\MyLicense 1 Test Plan1.doc’ to object ‘Object Repository/Page_Online Services/UploadSectionArea’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:860)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$4.call(Unknown Source)
at Application Checklist.run(Application Checklist:33)
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 TempTestCase1587130676872.run(TempTestCase1587130676872.groovy:23)
Caused by: org.openqa.selenium.ElementNotInteractableException: element not interactable
(Session info: chrome=80.0.3987.163)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘DAVEDICOCCO’, ip: ‘10.194.85.21’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.163, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389…, userDataDir: C:\Users\ddicocco\AppData\L…}, goog:chromeOptions: {debuggerAddress: localhost:65151}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 8e88cb62f8a3ae0c542928ca8c1215ba
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.CChromeDriver.execute(CChromeDriver.java:19)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy9.sendKeys(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.sendKeys(EventFiringWebDriver.java:429)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.doCall(SendKeysKeyword.groovy:53)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.call(SendKeysKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:860)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$4.call(Unknown Source)
at Script1587128736037.run(Script1587128736037.groovy:33)
… 11 more

here is the line of code in the script

WebUI.sendKeys(findTestObject(‘Object Repository/Page_Online Services/UploadSectionArea’), ‘C:\Documents\MyLicense 1 Test Plan1.doc’)

You’re not, trust me :blush:

At the moment before you try and upload the file, can you open your inspector and enter this into the Console:

$x(“//input[@type='file']”)

and see what comes back.

i think i did this right

You did, but the forum formatting messed up the double quotes “”.

Please retype delete/retype them in the console using your keyboard.

Right ok, so it can find the element. When you say above:

I’m assuming you tried using sendKeys() with the test object containing our custom xpath. When you say it “didn’t work”, what do you mean? Was an error thrown? Did it run without error, but no file was uploaded?

here is the line of code:
WebUI.sendKeys(findTestObject(‘Initial Application/Document Upload/UploadSectionArea’), ‘C:\Documents\MyLicense 1 Test Plan1.doc’)

here is the object

here is the error i get
04-17-2020 12:44:17 PM sendKeys(findTestObject(“Initial Application/Document Upload/UploadSectionArea”), “C:\Documents\MyLicense 1 Test Plan1.doc”)

Elapsed time: 48.934s

Unable to send keys ‘C:\Documents\MyLicense 1 Test Plan1.doc’ to object ‘Object Repository/Initial Application/Document Upload/UploadSectionArea’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to send keys ‘C:\Documents\MyLicense 1 Test Plan1.doc’ to object ‘Object Repository/Initial Application/Document Upload/UploadSectionArea’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:860)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$6.call(Unknown Source)
at Application Checklist.run(Application Checklist:28)
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 TempTestCase1587141715782.run(TempTestCase1587141715782.groovy:23)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Initial Application/Document Upload/UploadSectionArea’ located by ‘By.xpath: //input[@type=‘file’][count(. | //[@class = ‘MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary’ and (text() = concat(‘Drag ’ , "’" , ‘n’ , “'” , ’ drop files here, or click to select files.‘) or . = concat(‘Drag ’ , "’" , ‘n’ , "’" , ’ drop files here, or click to select files.'))]) = count(//[@class = ‘MuiTypography-root MuiTypography-body1 MuiTypography-colorTextSecondary’ and (text() = concat(‘Drag ’ , "’" , ‘n’ , "’" , ’ drop files here, or click to select files.‘) or . = concat(‘Drag ’ , "’" , ‘n’ , "’" , ’ drop files here, or click to select files.‘))])]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1154)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.doCall(SendKeysKeyword.groovy:52)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.call(SendKeysKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:860)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$6.call(Unknown Source)
at Script1587139663974.run(Script1587139663974.groovy:28)
… 11 more
)

You’ve got multiple locators checked in your test object. Make sure that our xpath is the ONLY one checked.

1 Like