Testcafé - getting content of invisible <input>'s value attribute

1k views Asked by At

I need to get the value of an <input>, specifically the stuff that is held inside its value attribute.

However, the input is not visible, so that seems to be a problem for testcafé.

Does anyone know how to work around that? Is there a special option you can use with the Selectors to make it work?

Thanks for helping me out, I appreciate any help!

2

There are 2 answers

1
fweidemann14 On BEST ANSWER

Got it, simply declare a Selector like this let yourInputs = Selector('input[type="hidden"]'), this will get all hidden inputs and return a NodeList which you can iterate over in your test.

If you want to be more specific and select over an ID or name, do it like @lumio.

Then you can access the value in your test run with an await yourInputs.value.

4
lumio On

I guess you mean a hidden input element as in <input type="hidden" /> and you want to receive the value before you're sending it to your Node application. You can use querySelector for this.

console.log( document.querySelector( 'input[name=test]' ).value );
<input type="hidden" name="test" value="hello world" />


For TestCafé you got the Selector-constructor which creates a selector.

As fweidemann14 pointed out, you can do the following:

const hiddenInputs = Selector( 'input[type="hidden"]' );