question

gkarumba avatar image
gkarumba asked ericnute edited

Variable substitution in target referred by xPath throws error

Getting an error that invalid substitution in field, while trying to specify the value in xPath using a variable.

 

getInnerText session ://td/table/tbody/tr[contains(td[2],$ctlr_ip)]/td[6];

 

See the attached screenshot for the exact error.

Message Edited by gkarumba on 10-23-2008 02:44 AM
iTestxpath
itest_error.GIF (15.3 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.

1 Answer

·
PaulD avatar image
PaulD answered PaulD posted

The problem here is that the square brackets in the xpath is being interpreted as a substitution command.  So you need to escape those brackets:

 

//td/table/tbody/tr\[contains(td\[2\],$ctlr_ip)\]/td\[6\]

 

If the escaping rules are confusing, another option is to concatenate different portions that allow or disallow substitutions (because of braces).  Note that you can only inhibit substitution on an argument to a substitution command.

 

[string concat {//td/table/tbody/tr[contains(td[2],} $ctlr_ip {]/td[6]}]

 

 

Message Edited by PaulD on 10-22-2008 02:42 PM
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.

gkarumba avatar image gkarumba commented ·
Thanks, Paul. It worked. Appreciate your help.
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.