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
Related
unable to capture guid from the below respose using regular expression
{"failure":[],"success":{"NativeMobile.CheckoutItem":["46724846133980208"]}}
using below regular expression, tried with different options
NativeMobile.CheckoutItem":["(.*?)"]
Please help to get the guid from above response
The response seems to be JSON
JSON is not a regular language
I think it would be much easier to use JSON Extractor instead, the relevant JsonPath query would be something like:
success.['NativeMobile.CheckoutItem'][0]
More information: How to Use the JSON Extractor For Testing
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
Below is a sample response from Jmeter tool
<ns2:Attribute Name="GUID" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>8b0f3dfe-21d3-1035-a063-f6571edcc101</ns2:AttributeValue>
</ns2:Attribute>
<ns2:Attribute Name="SCODES" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>S0336492^S0309824</ns2:AttributeValue>
</ns2:Attribute>
<ns2:Attribute Name="MODE" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
<ns2:AttributeValue>2</ns2:AttributeValue>
</ns2:Attribute>
</ns2:AttributeStatement>
I need to extract "AttributeValue>2" from the response. Tried using regex but that isn't working here. Can we do it with xpath extractor? Any help would be appreciated.
Disclaimer: the below XPath query isn't guaranteed to work as I need to see full response, next time please provide as much information as you can:
Using local-name function like:
//*[local-name()='Attribute']/text()='MODE'/child::*/text()
Using XPath Namespaces functionality:
define ns2 namespace under namespaces.config file (lives in the "bin" folder of your JMeter installation)
restart JMeter to pick the property up
you should be able to use the following XPath query
//Attribute[#Name='MODE']/AttributeValue/text()
See Using the XPath Extractor in JMeter guide for more information.
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