Hi, I am trying to work out how to set the value ‘ks-manual-search.png’ in to a label which forms part of a ‘browse for file’.
I’ve tried using the WebUI.UploadFile and WebUI.SetText but neither work for me.
My non-boot strap version of this works fine with WebUI.UploadFile but this one is causing me some issues!
Any thoughts appreciated. I know the answer is probably pretty simple but I can’t work out…yet!!
Here is a screenshot of the page and source. The label gets the required value manually by clicking browse and selecting a file, but I need to automate this.
ks-label|690x134
Firstly, the label gains the text of the chosen file(s) as a result of having browsed for them. In other words, you don’t set the label directly - so WebUI.setText()
will not work.
Working with your screenshot, you should be able to target the <input type="file" ...>
using WebUI.uploadFile()
.
WebUI.uploadFile(findTestObject('path\to\your\test_object'), 'ks-manual-search.png')
Hi Russ, thanks for the reply.
I have tried that but for some reason it never locates the element.
If I use the spy tool, it only ever gives me the label above the one you mentioned, so I have tried using the xpath, full xpath, and selector that I can get using chrome devtools but none of those work when I replace those respective values in the object repository.
xpath
//*[@id=“files_1_odpLanYV”]
full xpath
/html/body/div[1]/div[5]/form/div/div[2]/div[1]/div/div/div/input
selector
#files_1_odpLanYV
There are no iframes/frames in play here either…
When pasting in css or xpath like the above, I take it I can just select the appropriate selection method on the object and then paste in the locator? Or does it require values in the ‘Objects xpaths’ list as well?
Just realised the id’s generated are dynamic so never the same. Regardless, I have tried using the name which is static but that also does not work:
//*[@name=“files"]
yes. If you know what you are doing, do it.
No. There’s no “magic” or hidden capabilities here. If you know what you need, and/or the CSS is correct, use it. That’s another way of saying, “distrust the spy tool first”. The spy tool helps when you know nothing about the underlying page. If you’re prepared to open it up, dig in, dig out what you need, go for it.
I (and many others) never use the recorder/spy tool.
One way or another you need to click that browse button (the <input type="file"...>
element). That’s usually best achieved using WebUI.uploadFile()
.
It might surprise you to know, you don’t even need the Object Repository. You can (almost) free yourself of a big bunch of maintenance by getting rid of all of them.
But that’s another question… and another story…
https://docs.katalon.com/katalon-studio/docs/manage-web-test-object.html
Well I just tried with locator or //*[@name=“files"] again and now it is working.
I guess I must have made a mistake somewhere else, but hey…
Thanks for you comments Russ 
1 Like