Hi,
I have a bunch of text fields whose repository items follow this pattern:
.//input[#'code1']
.//input[#'code2']
.//input[#'code3']
and so on...
I would like to be able to do something like:
.//input[#'code'+$num]
where $num is a declared variable.
Is there a way to just tack on a specific number to the end using variables?
I don't want to include the word 'code' in the variable.
Thanks
Using variables in a repository
Re: Using variables in a repository
Hi Jack,
Since Ranorex is based on SharpDevelop, you can use the whole .NET Framework to realize your approach.
You could combine your variable and the string "code" within a user code method.
In order to clarify my intention, I uploaded a small sample solution.
Feel free to ask me, if you have any questions regarding my sample solution.
I hope I could help you.
Kind regards,
asdf
Since Ranorex is based on SharpDevelop, you can use the whole .NET Framework to realize your approach.
You could combine your variable and the string "code" within a user code method.
In order to clarify my intention, I uploaded a small sample solution.
Feel free to ask me, if you have any questions regarding my sample solution.
I hope I could help you.
Kind regards,
asdf
You do not have the required permissions to view the files attached to this post.
Re: Using variables in a repository
Hi,
To be able to use variables in repository xpaths, you must replace unique ID attribute with "normal" "ID" attribute and use regular expression, like this:
Unique ID attribute cannot be combined with regexes and variables. The only way, how to combine unique ID attributes with other attributes, is like this:
But this will not help you in this particular case.
To be able to use variables in repository xpaths, you must replace unique ID attribute with "normal" "ID" attribute and use regular expression, like this:
Code: Select all
.//input[@id~'code'+$num]
Unique ID attribute cannot be combined with regexes and variables. The only way, how to combine unique ID attributes with other attributes, is like this:
Code: Select all
.//input[#'code1'][@enabled='True']
But this will not help you in this particular case.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
Re: Using variables in a repository
While Pavel's approach is the correct and appropriate one for your case, note that you do not have (and might not want) to use the Regex operator ("~"). You can use the equality operator ("=") if you know for sure that the evaluated expression is going to match exactly.
If $num = 1:
.//input[@id~'code'+$num] <- Will find the first input with an id that has "code1" anywhere IN it.
.//input[@id='code'+$num] <- Will find only the first input that whose id equals exactly "code1"
If you have instances where you have the following IDs, you might not get what you want with the Regex operator looking for "code1", for example:
code1
code12
Xcode1
All of these would potentially be found with the regex version, depending on where they are in the app's document model, but the equality version would only find the first one ("code1").
If $num = 1:
.//input[@id~'code'+$num] <- Will find the first input with an id that has "code1" anywhere IN it.
.//input[@id='code'+$num] <- Will find only the first input that whose id equals exactly "code1"
If you have instances where you have the following IDs, you might not get what you want with the Regex operator looking for "code1", for example:
code1
code12
Xcode1
All of these would potentially be found with the regex version, depending on where they are in the app's document model, but the equality version would only find the first one ("code1").
Shortcuts usually aren't...
Re: Using variables in a repository
Hello,
Thanks for the little demo .sln, that helped.
I've successfully setup a Repository variable, applied it to a test module and bound it to a .csv data source in the TestCase.
Log file shows it the .csv values are being propagated through the repository variable. => Success!
However, getting the following error: "Invalid location string format: 'input1'
Here is the XPath: .//text[@text=$varBM]
Have tried a number of RegEx edits to the XPath, but no difference.
Help.
Thanks!
Thanks for the little demo .sln, that helped.
I've successfully setup a Repository variable, applied it to a test module and bound it to a .csv data source in the TestCase.
Log file shows it the .csv values are being propagated through the repository variable. => Success!
However, getting the following error: "Invalid location string format: 'input1'
Here is the XPath: .//text[@text=$varBM]
Have tried a number of RegEx edits to the XPath, but no difference.
Help.
Thanks!
Re: Using variables in a repository
Hi Hondo,
May I ask you to upload a Ranorex Snapshot of your application under test to the forum? This will allow us to check you RxPath.
Best regards,
asdf
May I ask you to upload a Ranorex Snapshot of your application under test to the forum? This will allow us to check you RxPath.
Best regards,
asdf
Re: Using variables in a repository
No sorry I cannot.. Proprietary concerns etc..
Hopefully this'll help.
Note: x64 WPF app.
Rooted Folder: .//container/container[3]/?/element[@automationid='Content']/?/container[@automationid='BookmarkersCtrlPanel']
=>Child Rooted Folder: .//container[@automationid='LayoutRoot']/?/list[@automationid='listBox_Bookmarks']/element[@automationid='Bd']
==>Child Rooted Folder: .//container/container/container?/element[@automationid='PART_ScrollContentPresenter']/list/container
===>List Item: listitem?/element?/?/text[@text='input1'] (this resolves just fine)
===>List Item: listitem?/element?/?/text[@text=$varBM] (passing in 'input1' generates "Invalid location string format: 'input1'" )
p.s. edit:
I can also go to the Action line in the module (Mouse>DoubleClick) and then select "HighLight Element" and it successfully resolves to 'input1'.. more proof the Repository variable is hooked up properly & the XPath definition is correct.
Hopefully this'll help.
Note: x64 WPF app.
Rooted Folder: .//container/container[3]/?/element[@automationid='Content']/?/container[@automationid='BookmarkersCtrlPanel']
=>Child Rooted Folder: .//container[@automationid='LayoutRoot']/?/list[@automationid='listBox_Bookmarks']/element[@automationid='Bd']
==>Child Rooted Folder: .//container/container/container?/element[@automationid='PART_ScrollContentPresenter']/list/container
===>List Item: listitem?/element?/?/text[@text='input1'] (this resolves just fine)
===>List Item: listitem?/element?/?/text[@text=$varBM] (passing in 'input1' generates "Invalid location string format: 'input1'" )
p.s. edit:
I can also go to the Action line in the module (Mouse>DoubleClick) and then select "HighLight Element" and it successfully resolves to 'input1'.. more proof the Repository variable is hooked up properly & the XPath definition is correct.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Using variables in a repository
Hi Hondo,
May I ask you to send an email to [email protected] with a detailed description of your issue?
We could arrange a remote session, if it is necessary. Then we would be able to analyze your issue directly on your machine.
Thank you in advance.
Sincerely,
Matthias
May I ask you to send an email to [email protected] with a detailed description of your issue?
We could arrange a remote session, if it is necessary. Then we would be able to analyze your issue directly on your machine.
Thank you in advance.
Sincerely,
Matthias
Re: Using variables in a repository
Just a follow up..
In an entirely different and new script, I made Repository variables work.
Even using two different data sources (Simple and CSV).
Worked well.
Not sure what the problem was in the original script. Will revisit it soon enough.
In an entirely different and new script, I made Repository variables work.
Even using two different data sources (Simple and CSV).
Worked well.
Not sure what the problem was in the original script. Will revisit it soon enough.