Below is a sample response from JMeter tool.
<input name="requestId" type="hidden" value="-1859748216"/>
I try the following XPath //input[#name='requestId'], but it doesn't work, I would like to take only the numeric value -1859748216
You need to get the value attribute using /#value
//input[#name='requestId']/#value
Prefer using newer/improved XPath2 Extractor over XPath Extractor
If you really want to use XPath, you need something like //input[#name='requestId']/#value
However XPath Extractor is quite resource intensive as it keeps entire DOM in memory, when it comes to getting the values from HTML content I would rather recommend going for CSS Selector Extractor leaving XPath for XML or when CSS Selectors are not powerful enough
Example setup:
More information:
CSS Selectors Reference
How to Use the CSS/JQuery Extractor in JMeter
Related
In JMeter, I'm trying to extract the values of property key values using CSS selector extractor, for the attached HTML body
I used the expression #propertySummaryList > div, but not seeing any response in debug sampler.
I would use Boundary Extractor, simpler and faster.
Use parameters:
Left Boundary : propertykey="
Right Boundary: "
Match No.: -1
Allows the user to extract values from a server response using left and right boundaries
Don't post code as image as it's way harder to reproduce your issue
Try out the following selector instead: div[class=propertySummaryList] > div
Demo:
More information:
CSS Selector Reference
How to Use the CSS/JQuery Extractor in JMeter
I tried to use JMeter recommendation to move to XPath2 over XPath Extractor
Since JMeter 5.0, you should use XPath2 Extractor as it provides better and easier namespace management, better performances and support for XPath 2.0
But for simple query I get no results, for output
<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D112345</Value></Property></Object>
I use query /Object/Property/Value or //Object//Property//Value and it works only in XPath and not XPath2
Results:
Value={abc-def}
Value_1={abc-def}
Value_2=D112345
Value_matchNr=2
Same results with /*[local-name()='Object']/*[local-name()='Property']/*[local-name()='Value'] as #EdBangga suggested
Is there an issue with XPath2 Extractor or major change of syntax?
Your issue is due to namespaces in your XML (i)
Once you show the full XML with namespaces I can give more information but to summarize:
you'll need to configure alias i to match the full namespace (you can use XPath2 Tester and Show Namespaces aliases)
then it should work
So I need to delete an "onclick" dynamic link using jmeter.
Here is the sample of one of the links:
"Delete"
What I need is to extract number and post it in order to do the delete action. Every link is the same except the number.
I have tried to implement some of the solutions I've found on this site but it didn't work.
Thanks in advance
Peace
If you need to do it with XPath you could try going for substring-after function like:
substring-after(//a[text()='Delete']/#href,'param=')
The above expression returns everything which is after param= text in href attribute of a HTML tag having Delete text.
You can test your XPath expressions against actual server response using XPath Tester tab of the View Results Tree listener.
References:
substring-after Function Reference
XPath 1.0 Language Reference
Using the XPath Extractor in JMeter
XPath Tutorial
What should be the Xpath query if I want to extract the value for access token, ie 93ee29b4-74dc-4uu7-8e10-6eac6845511b from below http response. I tried using the Xpath extractor with different xpath queries, but no luck.
{
"access_token":"93ee2tum-1234-56789-8e10-6eac684551tum",
"token_type":"Bearer",
"expires_in":3600,
"scope":"test"
}
Is there any reason you are using the xpath extractor instead of the regular expression extractor? Xpath is only useful in case there are for example multiple identical tags with different values.
Regular extractor:
access_token":"([^"]+)"
If you do need to use xpath you should know that it doesnt work with Json by default.
Read also: http://blazemeter.com/blog/using-xpath-extractor-jmeter-0
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]
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