最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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!

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!

Share Improve this question edited Jul 16, 2019 at 14:55 Alex Skorkin 4,2743 gold badges27 silver badges48 bronze badges asked Sep 10, 2017 at 18:14 fweidemann14fweidemann14 1,9933 gold badges14 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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.

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"]' );
发布评论

评论列表(0)

  1. 暂无评论