question

nkankipati avatar image
nkankipati asked ericnute edited

how to substitute variable in xpath query

 

 

mapped/Regex/Body/line[./get_image_size/image_name='c7200-adventerprisek9-mz.151-1.10.T*']/get_image_size/image_size <<< working


mapped/Regex/Body/line[./get_image_size/image_name="c7200-adventerprisek9-mz.151-1.10.T*"]/get_image_size/image_size <<< working


set imagename "c7200-adventerprisek9-mz"

set imagever "151-1.10.T"


mapped/Regex/Body/line[./get_image_size/image_name='$imagename.$imagever*']/get_image_size/image_size  <<< not working


mapped/Regex/Body/line[./get_image_size/image_name=\'$imagename.$imagever*\']/get_image_size/image_size  <<< not working


mapped/Regex/Body/line[./get_image_size/image_name=\"$imagename.$imagever*\"]/get_image_size/image_size  <<< not working


i tried several other ways also and searched lot of examples in forum by searcing with "xpath variable substitution""xpath substitution" returned lot of examples

but i couldn't get the solution... 

any help is appreicated.

 

what am i missing here ???

iTestxpath
10 |950

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

1 Answer

·
PaulD avatar image
PaulD answered PaulD posted

There are two things to understand:

 

1)  You must enable substitution on a query string.  By default, it is turned off (depending on where you are using it). 

 

2)  XPATH queries (including your example here) contain characters that are special for substitution.  In particular, the square brackets [ ] used for subqueries in XPATH also cause command substitution.  So if you enable substitution, you need to "escape" these special characters.

 

So if you enable substitution on your query, you will end up with something like this:

 

mapped/Regex/Body/line\[./get_image_size/image_name='$imagename.$imagever*'\]/get_image_size/image_size

 

All I've done is to put backslashes in front of the square brackets.

 

1 comment
10 |950

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

nkankipati avatar image nkankipati commented ·

thanks, Paul

 

after i click grey box, it turned into little "F" which is attached to the corner of the query text field in step properties, [enable substitution on a query string]

 

and it worked. 

 

 

0 Likes 0 ·

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.