gokul1809 avatar image
gokul1809 asked ericnute edited

Need to extract the XPath in a Response

I have a response in a test-step. The response is attached in the txt file.


As of now, I am not using any specific response map to query this output. However, I could find that the default "query" of iTest gives the following query map.




My question is the following:

I wanted to extract a part of the XPath of the "response".


For example: 

The following is the line in the response.txt


MIB-2::ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.84 = OctetString: XYZ=2-A-1-L1-1


I wanted to extract "84" from the above line. The line from which "84" has to be extracted has to be queried using "XYZ=2-A-1-L1-1", (i.e) XYZ=2-A-1-L1-1 is known by me and I wanted to use it as a query to extract/parse "84" from the data response.


Is there a way to do this in iTest ??

iTestresponse mapxpath
response.txt (11.4 KiB)
response.JPG (321.4 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image
PaulD answered PaulD posted

Yes.  You can use the following query to get what you're looking for:




This says, "Find the ifXEntry row where the ifName column has value 'XYZ=2-A-a-L1-1' and then return the value of the ifIndex column."



10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gokul1809 avatar image gokul1809 commented ·



In an attempt to extract the value "37" in line 1 of the response.txt, I used the following syntax.


Command: eval --- set result [query snmp_issue //ifXTable/ifXEntry[ifName='DCHCTP=1-A-3-L1-1']/ifIndex]


Here, "snmp_issue" is the variable that holds the entire response and "result" is the variable that is supposed to hold the value "37".

But, I am seeing the following validation error. Can you please look into this ?

Unable to evaluate "set result [query snmp_issue //ifXTable/ifXEntry[ifName=DCHCTP=1-A-3-L1-1]/ifIndex]" : command ifName=DCHCTP=1-A-3-L1-1 is not registered


MIB-2::ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.37 = OctetString: DTPCTP=1-A-3-L1-1



0 Likes 0 ·
PatrickH avatar image PatrickH gokul1809 commented ·

I believe you would need to escape the inner [ ] brackets. Resulting in:


set result [query snmp_issue //ifXTable/ifXEntry\[ifName='DCHCTP=1-A-3-L1-1'\]/ifIndex]


The reason is that command substitution is happening so the interpreter is trying to evaluate query as a command (which is correct) and then is also trying to interpret ifName=... as a command (which is not correct.)

0 Likes 0 ·
gokul1809 avatar image gokul1809 PatrickH commented ·

Still, there seems to be an issue with the query.


I used the following lines of code and got no response for the "puts" command.


Variables: snmp_issue (response.txt attached)


Command1: set result [query snmp_issue //ifXTable/ifXEntry\[ifName='TRIBPTP=1-A-3-L1-1'\]/ifIndex]  

Response1: NIL


Command2: puts $result  

Response2: NIL


I am attaching the test case herewith.

NOTE: I have queried the line 4 of the response.txt, so as to extract the value "40" and put it in the variable "result".

0 Likes 0 ·
response.txt (11.4 KiB)
forum.fftc (1.9 KiB)
PaulD avatar image PaulD gokul1809 commented ·

It's hard to tell from this what is going wrong.  Please do the following:


Open the Structure view and select the appropriate step in your test case.  Just as you are showing the Queries view in your screenshot, the Structure view will show all of the raw data available for analysis on that step.  There is a button in the Structure view's toolbar that will toggle it between table view and XML view.  In XML view, select all of the XML text there and post it here on the forum -- either as text or in an attachment, whichever is easier.


With this it will be easier to see what is going wrong with the query.


One question:  when you saved the "snmp_issue" response in a variable, are you sure you are saving the full response and not just the response text?  (There is a checkbox to control this.

0 Likes 0 ·
sreekanth avatar image sreekanth PaulD commented ·

I have contacted the customer and solved this issue.


Thanks Paul.

0 Likes 0 ·
PaulD avatar image PaulD sreekanth commented ·


0 Likes 0 ·
gokul1809 avatar image
gokul1809 answered gokul1809 posted

Attaching the screenshot to offer a better view.

response.JPG (319.5 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.