0
votes

Can anyone please help me here? I'm trying to do an http post in Jmeter, http works fine, but I'd like to extract the LastName value from the response to use in next http request. I've tried several methods using Xpath Extractor but the Debug sampler shows nothing. I've added XPath_Extractor as a child of HTTP Sampler. what am I doing wrong here?

Here is what I setup in the XPath Extractor

Reference Name = lstname (which is the variable I carry to next http request)

XPath Query = //*[local-name()='LastName']/text()

also tried

/Reply/CustomerData/@LastName

Main Sample checked

Use NameSpaces- checked

Ingnore whitepspaces checked

Here is my http response

<?xml version="1.0" encoding="UTF-8"?>

<dm:reply xmlns:dm="http://www.xx.com/dm" version="1.0">

<Session>

<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062362"/>
<Reply type="Connection">

<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</Reply>

<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062504"/>

<Reply type="Execute">
<CustomerData FirstName="" LastName="Moni" Address="SD" Chassis="AWD" CountryOfBirth="" CountryOfOriginFullName= Year="2010">
<RecordSet>
</RecordSet>
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</CustomerData>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062590"/>
</Session>
</dm:reply>
2

2 Answers

0
votes

You can use regular expression extractor - Post Processor to achieve this.

You need to fill in following parameters

  1. Reference Name: LastName
  2. The regular expression (would look like): LastName="(.*?)"
  3. Template: $1$
  4. Match : 1
  5. Default Value: NotFound

Use ${LastName} in next request to access extracted value of LastName. Add debug sampler to check if you are extracting correct value.

0
votes

Why do you need all this namespaces stuff?

  1. Don't check any boxes in the extractor
  2. Use //CustomerData/@LastName as XPath expression
  3. That's it

XPath Extractor

By the way, you can evaluate XPath Expressions directly against response using XPath Tester mode of the View Results Tree listener. See How to debug your Apache JMeter script article for more tips on getting to the bottom of your JMeter test issue.