Unable to upload using sendKeys

Hi,

I followed the instructions in How to resolve file upload issues but I am having no luck.

This is a web application.

Here’s where the script gets to:

The sendKeys statement executes but it doesn’t pick up the file.

When I check that the upload button is clickable, the script fails.

Here’s the test script:

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

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

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

// Get the project directory
String dirName = RunConfiguration.getProjectDir()

//Construct full path to the first file
String filePath1 = (dirName + GlobalVariable.DataFileFolder) + file1

println('Full path to file : '+filePath1)

WebUI.callTestCase(findTestCase('Login/CVIP Login'), [:], FailureHandling.STOP_ON_FAILURE)

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/a_Inspectors'))

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/a_Search Inspectors'))

WebUI.verifyElementText(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/h1_Search Authorized Inspector'), 
    'Search Authorized Inspector')

WebUI.setText(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/input_Search Authorized Inspector_searchInput'), 
    '200019')

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Search Authorized Inspector_btn btn-_60a73a'))

WebUI.verifyElementText(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/td_Scripps, Bernie Michael'), 
    'Scripps, Bernie Michael')

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/a_200019'))

WebUI.verifyElementText(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/h2_Scripps, Bernie Michael'), 
    'Scripps, Bernie Michael')

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Add Document'))

WebUI.selectOptionByValue(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/select_(Select One)Air Brake Training Endor_9f0947'), 
    'AB_TRAINING_ENDRSMT', true)

// let's see if this works
WebUI.sendKeys(findTestObject('FileUpload/FileUploadObject'), filePath1)

WebUI.verifyElementClickable(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload'))

WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload'))

WebUI.delay(3)

WebUI.verifyElementClickable(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Save'))
WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Save'))
2 Likes

Please show us the full log.

1 Like

Hi @consulting, See this posting: How-to use ‘sendKeys’ or 'File Upload' to upload files
**Please read the entire post.

1 Like

Thanks :grinning: - I followed the steps, updated the object and validated it.

Here’s the updated object

I added the wait statement:

WebUI.waitForElementVisible(findTestObject('FileUpload/FileUploadObject'),30,FailureHandling.OPTIONAL)

We get to the statement where it waits but the element is never visible, so it times out.

Here’s the stack trace:

15: waitForElementVisible(findTestObject("FileUpload/FileUploadObject"), 30, OPTIONAL)
2023-08-31 10:35:56.705 WARN  k.k.c.w.k.b.WaitForElementVisibleKeyword - Object 'Object Repository/FileUpload/FileUploadObject' is not visible after 30 second(s)
2023-08-31 10:35:56.706 DEBUG testcase.AI Upload Supporting Document   - 16: sendKeys(findTestObject("FileUpload/FileUploadObject"), filePath1)
2023-08-31 10:35:57.078 DEBUG testcase.AI Upload Supporting Document   - 17: verifyElementClickable(findTestObject("Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload"))
2023-08-31 10:35:57.731 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' is NOT clickable (Root cause: com.kms.katalon.core.exception.StepFailedException: Object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' is NOT clickable
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.doCall(VerifyElementClickableKeyword.groovy:83)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.call(VerifyElementClickableKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword.verifyElementClickable(VerifyElementClickableKeyword.groovy:96)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword.execute(VerifyElementClickableKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementClickable(WebUiBuiltInKeywords.groovy:566)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementClickable$9.call(Unknown Source)
	at AI Upload Supporting Document.run(AI Upload Supporting Document:50)
	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:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1693503308896.run(TempTestCase1693503308896.groovy:25)
)
2023-08-31 10:35:58.005 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to verify object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' to be clickable (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to verify object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' to be clickable
	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.VerifyElementClickableKeyword.verifyElementClickable(VerifyElementClickableKeyword.groovy:96)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword.execute(VerifyElementClickableKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementClickable(WebUiBuiltInKeywords.groovy:566)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementClickable$9.call(Unknown Source)
	at AI Upload Supporting Document.run(AI Upload Supporting Document:50)
	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:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1693503308896.run(TempTestCase1693503308896.groovy:25)
Caused by: com.kms.katalon.core.exception.StepFailedException: Object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' is NOT clickable
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.doCall(VerifyElementClickableKeyword.groovy:83)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.call(VerifyElementClickableKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	... 17 more
)
2023-08-31 10:35:58.007 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/AI Upload Supporting Document FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to verify object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' to be clickable
	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.VerifyElementClickableKeyword.verifyElementClickable(VerifyElementClickableKeyword.groovy:96)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword.execute(VerifyElementClickableKeyword.groovy:67)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementClickable(WebUiBuiltInKeywords.groovy:566)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementClickable$9.call(Unknown Source)
	at AI Upload Supporting Document.run(AI Upload Supporting Document:50)
	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:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1693503308896.run(TempTestCase1693503308896.groovy:25)
Caused by: com.kms.katalon.core.exception.StepFailedException: Object 'Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload' is NOT clickable
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.doCall(VerifyElementClickableKeyword.groovy:83)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementClickableKeyword$_verifyElementClickable_closure1.call(VerifyElementClickableKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	... 17 more

2023-08-31 10:35:58.020 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/AI Upload Supporting Document

Any suggestions as to next steps?

1 Like

Hi @consulting,
Your locator for FileUploadObject is: //*[@id="fileButton" and @type="file"] and works as expected. Do you have the correct locator for button_Upload, it might be something like: //*[@type="button" and contains(@id,'chooseFileBtn')]

This example might help: How-to use ‘sendKeys’ or 'File Upload' to upload files - #12 by Dave_Evers

See: File Upload Sample - West Wind Web Connection
The xpath for Select images is: //*[@id=“upload” and @type=“file”]
The xpath for Upload is: //button[starts-with(@type, ‘submit’) and contains(@class,‘btn’)]


1 Like

Thanks @Dave_Evers1 - I made some tweaks to the script and checked the objects using F12 and I can find it.

Normally the flow is user clicks an “Add Document” button. The “Add Supporting Document” modal appears and the user picks an entry from the Document Type dropdown, then clicks ‘Choose file’, browses to the file and selects it and then the file input filed gets filled in.

The sendKeys statement never executes as that hidden input never becomes visible.

I am wondering if this is a case of where the Devs need to re-think the file upload piece of code or if there’s another way.

I have used your example and run it against the same site and it works as expected. The only difference between the sample and the site I am testing is the popup window appearing.

Any suggestions?

WebUI.selectOptionByValue(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/select_(Select One)Air Brake Training Endor_9f0947'), 
    'AB_TRAINING_ENDRSMT', true)

// let's see if this works
if (WebUI.waitForElementVisible(findTestObject('FileUpload/FileUploadObject'),10,FailureHandling.OPTIONAL)==true)
{
	WebUI.sendKeys(findTestObject('FileUpload/FileUploadObject'), filePath1)

	if (WebUI.verifyElementClickable(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload'))==true)
	{
		WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Upload'))
		WebUI.delay(3)
	
		if (WebUI.verifyElementClickable(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Save'))==true)
		{
			WebUI.click(findTestObject('Object Repository/AI Upload Supporting Document/Page_VIP/button_Save'))
		}
		else {
			println('ERROR: Unable to click the save button')
		}
	}
	else {
		println('ERROR: Unable to click the upload button')
	}
}
else
{
	println('ERROR: The file upload object did not become visible')
	assert false: "Unable to complete test - file upload object not visible"
}

Hi @consulting (Jonathan),
Have you tried using document.querySelectorAll("input[type=file]") to find the hidden element. See: How-to use ‘sendKeys’ or 'File Upload' to upload files for details.

1 Like

Thanks @Dave_Evers - I followed both your posts to the letter - I can get them to work with the sample site.

For my target, I confirmed I have the right xpath statement as I tried to illustrate in the following image

Running out of ideas and I haven’t seen any other posts in the forum or elsewhere for people having the same issue.

I am open to ideas… and THANK-YOU for all the time you have spent responding - much appreciated!!

1 Like

Jonathan, Why are you using == true
Not sure it would cause any issues …

if (WebUI.waitForElementVisible(findTestObject('FileUpload/FileUploadObject'),10, FailureHandling.OPTIONAL)==true) {
    //Do something
}

And not:

if (WebUI.waitForElementVisible(findTestObject('FileUpload/FileUploadObject'), 10, FailureHandling.OPTIONAL)) {
    //Do something
}

Could your object(s) be inside an iframe?
Use the DevTools (F12 ) console to search for any iframes:

document.querySelectorAll("iframe").length //iframe count
document.querySelectorAll("iframe") //displays actual frame(s)

Try it out here: <iframe>: The Inline Frame element - HTML: HyperText Markup Language | MDN

1 Like

Thanks for the suggestion - I removed the ==true (just a rookie thing) and re-ran the script - no change :frowning:

I also checked for iframes and it doesn’t look like there are any

1 Like

Hi @Russ_Thomas, Would you have any suggestions?

1 Like

@consulting

Use WebUI.setText() to populate the document field with your filename and path.

image

Click the Upload button:

image

If that doesn’t work, we’re missing some key piece of information, somewhere.

A couple things I read that I wanted to comment on…

You referred to a “popup window”. It’s not a popup window. It’s likely just a div element hosting a bunch of HTML.

You said:

If it works for users, it’s fine for testing. If you can’t test it, look to yourself, first.

As you discovered, it’s a waste of time checking visibility of elements with a hidden attribute.

1 Like

I just perused the HTML code… here’s what I found (though none of it helps with your current issue, it might be worth mentioning to the devs).

It has a broken structure. There is a <script> element as a first child of the document <html> element. That’s not legal HTML and makes a mockery of the <!DOCTYPE> preamble instruction. Whatever system the devs are using to build out there site, needs a thorough review.

image
<html>: The HTML Document / Root element - HTML: HyperText Markup Language | MDN

Then I found this:

<label>&nbsp;</label>

23acc64acfbdc1bf125c6f08043085ed-2984302642

Funniest HTML I’ve seen in a looong time. That’s like, “Hmm, I need a little box type thing so I can keep some space in it. I know! A car glove-box! Hmm. Where can I buy a car?”

1 Like

Another thing that is for information only; you are using the boolean as true in the above statement. The true means you want to use RegEx (Regular Expression), but you do not have any Regular Expression characters in your reference, 'AB_TRAINING_ENDRSMT'. You should change the boolean to false so you have a normal comparison.

A RegEx comparison would be like ^AB_T\\D{5-15} or AB_T.*