Can't find Input type=file

@Brandon_Hein: I am having trouble finding an object that has type=“file”.Please guide me on this.

@Preet

The page is using delegation, it seems. To find the input element, move to the Console and type this:

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

Hopefully, that will find the input element if it exists. If you see this image printed in the output, click it. That will take you to the element in the DOM. From there you should be able to create a CSS/XPath selector/locator to use in your script.

@Russ_Thomas :Thank you so much for your response so it worked for me and i could find the X-path.So from here i created a manual test object and provided it X-path and now using this test object to upload file for me.But i am still getting an error ,felt like X-path is keep on changing and that is the issue.I am very new in automation so a detailed steps would help me to understand better.Please see attached error details, manual object and script below for clarity:

Can you share more of the HTML surrounding that input element? If you click on the result of your query, it should bring you to the place where it exists in the HTML. We need to create an xpath for you that doesn’t rely on the ID value.

@Brandon_Hein Thank you much for your quick response but actually due to company polices ,i can’t share much details and if you can just suggest me something to look at that would help me to create an X path by myself.

No problem, I understand.

The input element itself doesn’t have any other useful attributes to uniquely identify it, so you’ll need to use some of the surrounding elements to do so. For example, if the input has a parent <div> element which has a unique, non-dynamic attribute, you could locate that, then traverse down to your input.

@Preet It’s likely you only have one <input[type=file]> on the page. You can target that element directly without an id attribute. @Brandon_Hein can give you the xpath.

Brandon?

I don’t need no stinkin xpaths :laughing:

1 Like

Sure, if it’s the only one of its type, you can use:

//input[@type='file']

1 Like

@Russ_Thomas @Brandon_Hein thank you so much for all your support and guidance and finally this xpath is working for me :)))))

2 Likes

@Russ_Thomas @Brandon_Hein Now i have an object fileUpload with X path=//input[@type=‘file’] and although i am able to click on browse and its taking me to the file but still getting failed to upload it and in errors getting “Object is null” .please give these a look error

Show me the script that uses that object.

@Russ_Thomas please look at the script and the object detail.

Don’t click Browse and don’t click Upload, just try…

WebUI.waitForElementPresent(findTestObject("the-new-object"))
WebUI.uploadFile(findTestObject("the-new-object"))

the-new-object is the one we created earlier. If that gives you the same error, paste the text of the xpath here.

@Russ_Thomas Is this how you mean to use X-path directly in my script?

WebUI.waitForElementPresent(findTestObject(’//input[@type=‘file’]’))

WebUI.uploadFile(findTestObject(’//input[@type=‘file’]’), ‘/Users/harpreetdhindsa/dp.jpeg’)

but Katalon is not accepting this code.

Can you try an experiment and go back to your code you have above and change your file pathway to use double slashes, like below?

"C:\\Users\\harpreetdhindsa\\dp.jpeg"

You may have to put in the full pathway, from the actual drive letter etc., to allow Katalon to “find” your file.

@grylion54 I have tried double \ ,\ and // ,/ ,but nothing is working for me.

No. The new Test Object (with the new XPATH).

@Russ_Thomas :In my test case new Test Object=fileUpload so according to that i have created script as per your instructions and please look at the results its still throwing errors!,now it not clicking browse and upload and also not even seeing that robot has opened photo path ,it stayed on browse page only and didn’t see any upload

  1. Make sure you have a working xpath – test it in the browser console $x(your xpath here).

  2. Show me the entire error message output.

I notice the complaint is about the next statement.

@Russ_Thomas so i have checked for the X-path in console and you can see attached screenshot.Actually on my page we click on browse and then photo is being uploaded and later Upload button turns to active and when you click on upload then we come to continue button.So here in the script we are not clicking browse and upload button and relying on Xpath object(fileUpload) to do all the work and when you execute this script it keeps you on (browse and upload button) page and we are never coming to continue button page and that’S

s why we can’t find the element a_Continue.