Hi,
As an example, say I have the following xpath which is looking at a cell in a table:
/dom.../text[@caption='JohnDoe']
Is it possible in the code (we are using c#) to search for the appropriate text value?
EG., could I do something to the effect of:
var aCell = @"/dom.../text[@caption='+varName+']
where "varName" is a value we are reading from an excel doc.
The intention is to be able to create a way of finding an item in the table whose name may be changed (which would be reflected in the excel doc) and then perform, say, a Click action, or verify it exists, etc. So we would have the repo item and change the part which is not going to remain constant (in this case, the name).
Can this be done?
Thanks!
Working with XPath in code
Re: Working with XPath in code
You can absolutely do that, but you need to structure the string correctly. You can do it one of two ways:
Code: Select all
var aCell = "/dom.../text[@caption='"+varName+"']";
// Notice the addition of "..." for a proper .net string, so you would have ...<single-quote><double-quote> +
// varName + <double-quote><single-quote>]<double-quote>.
// or, my preference for readability...
var aCell = string.Format("/dom.../text[@caption='{0}' and @id='{1}']", varName, varID);
// This is the .net in-line formatter. You use "{<index>}" in the spot in the string where you want the variable
// in that spot in the following list placed in the string.
// Format(<string to be formatted>, <0-index argument>, <1-index argument>, ... <n-index argument>).
Shortcuts usually aren't...
Re: Working with XPath in code
I have also a Question about this. I created a variable which conatins an Xpath to a Table Cell with described Method. How can i now get the value of this cell into another Variable?
Re: Working with XPath in code
Could you post your XPath and the code you are using?
Also, please include the following information when you have questions as it will help us understand what you are using:
1. What version of Ranorex are you using?
2. What version of Windows are you using?
3. What technology is your System Under Test (SUT) developed in?
Also, please include the following information when you have questions as it will help us understand what you are using:
1. What version of Ranorex are you using?
2. What version of Windows are you using?
3. What technology is your System Under Test (SUT) developed in?
Shortcuts usually aren't...