Can you set value to a hidden text field?


This is my 1st day trying Katalon and so far im liking it.

Got stuck to a concept on how to set a value to a hidden field.
Thank you very much in advance.


What do you mean by ‘a hidden field’?
If you want to be answered, you should at least show how your target HTML is coded.


on a simple page I have a:

How can I automate setting value to that invisible textbox?
thank you

Firstly, there is no direct way the user could do what you are trying to do, so strictly speaking, your test(s) should not do that either. Can I first suggest you re-analyze what you need to do in the test and see if that moves you forward…

That being said, you could set the value of that input element using JavaScript. There are many threads here that talk about using JS to target HTML elements. Here’s one:

1 Like

I have to agree. If it’s not something the user can do through a series a click actions, it’s not really a valid test. Is there a particular reason to perform this set of actions? Perhaps the object becomes visible after selecting another option and then should be set?

1 Like

First, Check that Katalon can see it. Use “Verify element visible” and “verify element present”

If Katalon can’t see it, then you will need to use some alternative method to do your test case.

I encountered a similar scenario. When I click a button in the page, it will pass the visible text to a hidden one and transfer it to the next page. So I need to set value of the hidden text.

Finally, I found setText could set value to the hidden element and therefore transferred to the next page as expected.

Can you please tell how you did this?

Hi… if you open the DevTools via F12, and fill in the text box a value.
in the DevTools, you should be able to see two fields are updated with the same value. One is the visible text box and the other is the hidden field.

Use key word setText to pass the value to this hidden field directly. Then it should work.

1 Like

I strongly agree, however, last week i was on course about security testing. Ability to set values to invisible field would be needed if one wants to implement regression security testing. (since all security testing is basically exploiting existing features of application).

100% agree with that. Modifying hidden and even readonly fields from JavaScript is very easy. And the reason I said “Strictly speaking…” is because normally our automation user is meant to be a regular site visitor and not a hacker with malicious intent.

Where was the course, Andrej? Is it available (or are any of the materials available) online?

Even with the restrictions you have mentioned, @Russ_Thomas, I cannot agree to this without reservation. Depending on the concrete task, I can well imagine (or was just faced with the question myself) that you occasionally need such tricks. First of all, I think it’s good to remember that although Katalon Studio may be specifically designed for testing requirements, it doesn’t really need to be “misused” for more general automation requirements.

That said, I don’t even have to go so far as to use it for scraping purposes, for example - even if that wouldn’t be a general and completely absurd approach in my eyes. Just imagine that complicated manual setup steps are necessary to set your AUT or even a special feature to be tested to a defined initial state. Why then make this preparation process unnecessarily error-prone if you can simply write a value in a hidden field?

That’ s why thanks for the tip with setText(), @Xing_Chen!

Agreed. I used words like should, not must or must not. There are always caveats. I made similar points somewhere on the forum about bypassing (what I called) the “gatekeepers”. Sometimes you have to sneak in over the fence. :confused:

Meanwhile I had to find out that the setText() tip unfortunately doesn’t help me, because I’m not dealing with a not only invisible input field of type=“text” but with a real hidden field of type=“hidden”.

In this case I probably can’t avoid injecting Javascript. My hack now looks like this:

List hiddenFormElm = WebUI.findWebElements(findTestObject(‘input_hidden’), 30)
WebUI.executeJavaScript(“arguments[0].value = ‘my form entry’”, Arrays.asList(hiddenFormElm))

Maybe somebody could use it.

agreed. buut … usualy pentesting involves some manual research on the ‘target’. and once you figure out some possible atack vectors, it’s only a matter of scripting. any basic tool can do it without particular features … since once you can do it manualy, you can program it too :slightly_smiling_face:
it’s only a matter of the tester skills …
just saying …

LE: not to mention that are already popular tools ‘in the wild’ any kido’s can use for such purpose

Just wondering why you talking about “a real hidden field” and actually handling an array of fields WebUI.findWebElements

FYI: hidden fields with a name attribute are submitted by a form over HTTP. You could target a specific hidden field directly using CSS (and not have to deal with an array).

String js = '''
 document.querySelector("input[name='whatever']").value="my value";
WebUI.executeJavaScript(js, null)

if is present into the html / DOM, is not hidden :smile:
just pretending …

You are actually right, thanks for your addition regarding the CSS syntax. It is still necessary to execute Javascript code, which I would like to avoid. In addition, I don’t want to reference the element directly in the code but use the test object abstraction layer provided by Katalon Studio.

But the reason why I use WebUI.findWebElements in my special case was that I actually have to fill several fields that have to be iterated because of an unclean DOM (identical ID). So my code was not complete, but even very special. :slight_smile:

1 Like

OK, agreed too. :slight_smile: