Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the value from a hidden input field using JMeter

Tags:

jmeter

I am trying to get the value from a hidden input field. I researched and found many sites ( including instances on this site ) showing great examples. When I try them, I am not able to retrieve the value from this hidden field using the methods I have learned. I have tried both an xpath extractor and a regular expression extractor, but neither one retrieves the value from the hidden field.

Also, I will note that in the tree on the left side in JMeter, I put the extractors as a child to the HTTP Request where the token first appears. Are the extractors supposed to be children or are they supposed to be at the same level as the HTTP Request, but just after it in the flow of the test?

==============================

Here, I will explain my set up. There is an HTTP request from a form. There is a token on the form. I need to get the value for this token. Here is the html for the page where the token appears:

<form action="/folder1/part1/save/12345-1234-1234-1234-123456789012" method="post" name="mgr" id="mgr" >
<input type="hidden" name="token" value="1234-12-12-12-1234" id="token" />

==============================

For the Regular Expression Extractor, I have tried all of these, one at a time for each test run:

//input[@type="hidden" and name="token"]/@value
//input[@type="hidden"][@name="token"]/@value
//input[@type="hidden"]/[@name="token"]/@value
//input[@type="hidden"][@name="token"]/@value/[@id="token"]
//input[@type="hidden"]/[@name="token"]/@value/[@id="token"]

For the XPath Extractor, I have tried all of these, one at a time for each test run:

//[@id="token"]
/html/body/div/div[2]/div/form/input[1]
//html/body/div/div[2]/div/form/input[1]
like image 726
toolmania1 Avatar asked Jan 29 '14 16:01

toolmania1


People also ask

How do you use hidden form fields?

Hidden form field is used to store session information of a client. In this method, we create a hidden form which passes the control to the servlet whose path is given in the form action area. Using this, the information of the user is stored and passed to the location where we want to send data.

What are hidden form values?

The hidden value of type defines a form field that is never displayed to the user. The user cannot change the value of the field, or interact with it. When the user submits the form, all of the data they have entered is sent, including the data stored invisibly in the hidden fields.


1 Answers

Try this one: //input[@type="hidden" and @name="token"]/@value

Also, you could test your expressions exactly in JMeter. For example, this xpath extraction you could check in XPath Tester element in View Result Tree Listener. There you could find Regexp Tester too

like image 114
Jay Avatar answered Jan 02 '23 12:01

Jay