Good day to all,
I am just starting my Ranorex journey, so forgive me if I am missing the basics.
My goal is to get a dynamic value and paste it.
I assume I would be using the GetValue and SetVaule actions. However, I do not know the proper syntax or what attribute to reference.
"/form[@title='Confirm Device Reset']/text[@text='Reset will delete all information and restore your device back to factory settings.If you wish to continue, enter the following digits:26553 ']//div[#'confirmation']/p[@innertext~'digits:*']" ???
I appreciate the assistance,
thanks
How get a dynamic value and paste it.
How get a dynamic value and paste it.
You do not have the required permissions to view the files attached to this post.
Re: How get a dynamic value and paste it.
Hi kcochran, welcome to the forums!
This is an excellent question! The answer will depend on the structure of your application a bit. If you can target just the digits, it will be just as easy as you outline: Get Value (store this value as a variable) and then Set Value.
If the entire section "If you wish to continue, enter the following digits: 20752" is one text element, then you'll likely need to use a User Code Method to parse out the digits. For the User Code Method, I would use pass in the text object, use String.Format (or another method that can concatenate strings) to grab the last 5 digits, and then have the method return that result (which you can then store in a variable). From there you should be able to pass that value to the empty text box. As an example, the code would probably look something like this in C#:
These are just two methods, but if you provide a Snapshot of the application, we may be able to provide some additional methods or insight. I hope this helps point you in the right direction!
--Jacob
This is an excellent question! The answer will depend on the structure of your application a bit. If you can target just the digits, it will be just as easy as you outline: Get Value (store this value as a variable) and then Set Value.
If the entire section "If you wish to continue, enter the following digits: 20752" is one text element, then you'll likely need to use a User Code Method to parse out the digits. For the User Code Method, I would use pass in the text object, use String.Format (or another method that can concatenate strings) to grab the last 5 digits, and then have the method return that result (which you can then store in a variable). From there you should be able to pass that value to the empty text box. As an example, the code would probably look something like this in C#:
public void grabDigits(Adapter argument1) { var result = argument1.Element.GetAttributeValueText("Text"); //Get the text value result = result.Substring(result.Length - 4); //Only pull the last four digits digits = result; //Store those digits in the "digits" variable which we can access back in the Recording Module (see below) }In this example, I have a local variable in my recording called "digits" where I'm storing the result of the previous line's Substring action. This User Code Method grabs those digits and stores them in the "digits" variable so you can then use Set Value to pass the value from the "digits" variable into the empty Text Box.
These are just two methods, but if you provide a Snapshot of the application, we may be able to provide some additional methods or insight. I hope this helps point you in the right direction!
--Jacob
Re: How get a dynamic value and paste it.
Jacob,
Thanks for the warm welcome and the help!
Yes, the entire section is one element, so I guess I will need to read up on the user code method. But attached is the snapshot as requested. If you have any advice after you take a look at the snapshot, please let me know.
Again, thanks for the assistance!!
Thanks for the warm welcome and the help!
Yes, the entire section is one element, so I guess I will need to read up on the user code method. But attached is the snapshot as requested. If you have any advice after you take a look at the snapshot, please let me know.
Again, thanks for the assistance!!
You do not have the required permissions to view the files attached to this post.
Re: How get a dynamic value and paste it.
Hi kcochran!
It does look like User Code will be the best option (although others in the community may have other thoughts on the matter). The code provided in my last post will work, the only change I would make is to use Length - 5 (instead of Length - 4) to get the last 5 characters. As long as the structure of that text field doesn't change that should work.
--Jacob
It does look like User Code will be the best option (although others in the community may have other thoughts on the matter). The code provided in my last post will work, the only change I would make is to use Length - 5 (instead of Length - 4) to get the last 5 characters. As long as the structure of that text field doesn't change that should work.
--Jacob
Re: How get a dynamic value and paste it.
Hi,
In my opinion, the easiest (and codeless) way to get the value from string like this, is to use Get Value action with regex like this:
[^:\s]+$
This should get the numeric value behind colon. So you don't have to use code at all Simply enter the regex to "regex capture" field and Get Value should do the rest.
In my opinion, the easiest (and codeless) way to get the value from string like this, is to use Get Value action with regex like this:
[^:\s]+$
This should get the numeric value behind colon. So you don't have to use code at all Simply enter the regex to "regex capture" field and Get Value should do the rest.
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: How get a dynamic value and paste it.
You know, I never noticed the "Capture regex" option in the Get value Smart Action before. Good call, odklizec!odklizec wrote: ↑Tue Sep 21, 2021 7:24 amHi,
In my opinion, the easiest (and codeless) way to get the value from string like this, is to use Get Value action with regex like this:
[^:\s]+$
This should get the numeric value behind colon. So you don't have to use code at all Simply enter the regex to "regex capture" field and Get Value should do the rest.
--Jacob
Re: How get a dynamic value and paste it.
odklizec and Jacob ,
I appreciate the assistance with this problem.
Odklizec: the input would be like this??
So the "/form[@title='Confirm Device Reset']/text[@text='Reset will delete all information and restore your device back to factory settings.If you wish to continue, enter the following digits:26553 ']//div[#'confirmation']/p[@innertext~'digits:[^:\s]+$]"
I appreciate the assistance with this problem.
Odklizec: the input would be like this??
So the "/form[@title='Confirm Device Reset']/text[@text='Reset will delete all information and restore your device back to factory settings.If you wish to continue, enter the following digits:26553 ']//div[#'confirmation']/p[@innertext~'digits:[^:\s]+$]"
Re: How get a dynamic value and paste it.
Hi,
No, you don't need to apply the regex in the xpath. The xpath should look like this:
And then apply the regex I provided in recording action Get Value, like this:
No, you don't need to apply the regex in the xpath. The xpath should look like this:
Code: Select all
/form[@title='Confirm Device Reset']/text[@text~'following digits:']
You do not have the required permissions to view the files attached to this post.
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: How get a dynamic value and paste it.
Ok, I think I got the Get Value figure out. Now the next step is to get in the textbox. I am having trouble with that. See snapshot and error log.
You do not have the required permissions to view the files attached to this post.
Last edited by kcochran on Tue Sep 28, 2021 5:03 pm, edited 1 time in total.
Re: How get a dynamic value and paste it.
You do not have the required permissions to view the files attached to this post.
Re: How get a dynamic value and paste it.
Hi,
The problem is, that the xpath for given element apparently contains variable string and generally too many words. You must manually optimize the xpath, by removing all variable strings and eventually find better attribute for identification purposes.
The problem is, that the xpath for given element apparently contains variable string and generally too many words. You must manually optimize the xpath, by removing all variable strings and eventually find better attribute for identification purposes.
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