How to place a Variable into Xpath expression?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to place a Variable into Xpath expression?
Hello,
I want to modify an Xpath expression and include a Project Variable into it.
Instead of using //gub-beratercard/mat-card[contains(., 'Jonathan')], I want to replace 'Jonathan" with a variable from my project.
I tried to use //gub-beratercard/mat-card[contains(., 'Project.Variables.ConsultantName')], with and also without quotes around the variable, but with no success.
Could you please help me find out how to place a variable into this Xpath expression?
Thanks!
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1) I don't know if that's even possible in TestComplete. How would XPath know to interpret that? Maybe @AlexKaras knows.
2) Are you required to use XPath?
Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Just concatenate your template XPath string with the value stored in the variable.
E.g.:
var strXPath = aqString.Format("//gub-beratercard/mat-card[contains(., '%s')]", Project.Variables.ConsultantName);
And I agree with Marsha: try to avoid XPath in TestComplete unless you are considering cross-platform testing.
/Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your answer!
I`m not required to use Xpath, but it feels more natural and simple for me to use Xpath/CSS.
So, if I want to avoid Xpath, I should be able to place a variable inside the Value of the contentText.
I switched to the conditional and I saw that "contains" condition is not an option there, but for reaching this, I should use wildcard before/after the value.
My question here is: I am able here to place a variable + a wildcard? The options for the "contentText" value are Constant, Project Variable and Property, but nothing like code syntax where I can combine a variable + wildcard.
Thank you in advance!
Cristian
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Correct, code expression is not an option for the value in NameMapping.
I am not sure if you really need to use Conditional mode, but in order to emulate 'contains' you must append asterisk symbol to the value of the Project Variable used in NameMapping before referring to the object that uses this given variable.
E.g.:
Project.Variables.SomeVar = '*' + Project.Variables.SomeVar + '*';
...
/Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
