[英]Get attribute value of hidden form element
I´m using Postman to automate some tests. 我正在使用Postman来自动化一些测试。 I need to get the value of the value attribute on the hidden field with the name "execution": 我需要在名称为“ execution”的隐藏字段上获取value属性的值:
<form class="app-form" method="post" id="fm1" action="login" _lpchecked="1">
<input type="hidden" name="execution" value="633ffc0f">
</form>
In postman, there´s only cheerio available for this. 在邮递员中,只能使用这种方法。 I´ve tried variations of the following, but none is working: 我尝试了以下方法的变体,但没有一个起作用:
$('input#execution').attr("value");
$('input[name=execution]').attr("value");
$('input[type=hidden]').attr("value");
$(':hidden#execution').attr("value");
$('input:hidden[name=execution]').attr("value");
Many thanks! 非常感谢!
This is how you get value 这就是你获得价值的方式
const executionValue = $('input[name="execution"]').val();
console.log(executionValue);
https://jsfiddle.net/chille1987/3dap9yk4/2/ https://jsfiddle.net/chille1987/3dap9yk4/2/
input[name=execution]
does work fine for me input[name=execution]
确实适合我
console.log($('input[type=hidden]').attr("value")); console.log($('input[type=hidden]').val());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form class="app-form" method="post" id="fm1" action="login" _lpchecked="1"> <input type="hidden" name="execution" value="633ffc0f"> </form>
用它来获取价值
$('input[name="execution"]').val();
Using your example HTML snippet, you could use this basic code in the Tests
tab to save that value to an environment variable in Postman: 使用示例HTML片段, 可以在“ Tests
选项卡中使用以下基本代码将其值保存到Postman中的环境变量中:
const $ = cheerio.load(pm.response.text());
pm.environment.set("hiddenValue", $('input[name="execution"]').val());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.