I have a path like this /form/container/list[@classname='ListBox']/listitem/text[1]
This should return the first textbox of all listitems in a list. But the C# type in the *.cs file of the repository is Ranorex.Text. Therefore I can't use foreach.
How can I a list of items via repository without using index variables?
Change C# type of repository item
Re: Change C# type of repository item
If you want to get the whole list you will need to use the Find<T>(RanoreXPath) method, which returns a list of type <T> where all items match the given RanoreXPath.
Also, you can see the Ranorex API here: http://www.ranorex.com/Documentation/Ranorex/
Also, you can see the Ranorex API here: http://www.ranorex.com/Documentation/Ranorex/
Shortcuts usually aren't...
Re: Change C# type of repository item
Thanks but that's only a bit helpful. You could at least point to the Find Method in the documentation or give a short example. Does the Find method search for that very same element and casts it to the given type (in this case a list)?
Is it like:
Ranorex.Text myElement = repo.ElementXY;
List<Ranorex.Text> myList = myElement.Find<List<Ranorex.Text>>();
Or like:
Ranorex.Text myElement = repo.ElementXY;
List<Ranorex.Text> myList = Ranorex.Find<List<Ranorex.Text>>(myElementInfo.Path);
I don't get why the documentation tells me form//button gives me all the buttons in a form but in the background to my knowledge it's a property of type button.
I'll try it on monday...
Is it like:
Ranorex.Text myElement = repo.ElementXY;
List<Ranorex.Text> myList = myElement.Find<List<Ranorex.Text>>();
Or like:
Ranorex.Text myElement = repo.ElementXY;
List<Ranorex.Text> myList = Ranorex.Find<List<Ranorex.Text>>(myElementInfo.Path);
I don't get why the documentation tells me form//button gives me all the buttons in a form but in the background to my knowledge it's a property of type button.
I'll try it on monday...
Re: Change C# type of repository item
If you don't understand these basic principles of Ranorex and .NET programming, then my suggestion would be to read the Ranorex documentation and user guide (http://www.ranorex.com/support/user-guide-20.html) and then read about .NET programming, specifically with respect to C# and object oriented programming.
The API that I pointed to gives a minimal amount of information assuming that you understand .NET and Ranorex in general.
If you don't understand the nomenclature "Find<T>(RanoreXPath)" and such, then my suggestion is that you are either going to need to learn more or not do what you are trying to do.
The API that I pointed to gives a minimal amount of information assuming that you understand .NET and Ranorex in general.
If you don't understand the nomenclature "Find<T>(RanoreXPath)" and such, then my suggestion is that you are either going to need to learn more or not do what you are trying to do.
Shortcuts usually aren't...
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Change C# type of repository item
Hello haniball,
Below you can find a sample, which shows one way to use the Find()-method.
In my sample I'm using a simple form, which contains three text boxes.
The textbox-elements have the following paths:
/form[@controlname='Form1']/text[@controlname='textBox1']
/form[@controlname='Form1']/text[@controlname='textBox2']
/form[@controlname='Form1']/text[@controlname='textBox3']
Beginning from the form-element I start searching for all elements of type Ranorex.Text, which match the path "./text".
These elements are stored to a list.
Now we can loop through the list and write each text value to the Report.
We could also use the path ".//text", which identifies all buttons that are descendants of the form.
More information about the RanoreXPath can be found in the user guide.
Please let me know if you need more information.
Regards,
Johannes
Below you can find a sample, which shows one way to use the Find()-method.
Code: Select all
public IList<Element> Find(
RxPath path
)
The textbox-elements have the following paths:
/form[@controlname='Form1']/text[@controlname='textBox1']
/form[@controlname='Form1']/text[@controlname='textBox2']
/form[@controlname='Form1']/text[@controlname='textBox3']
Beginning from the form-element I start searching for all elements of type Ranorex.Text, which match the path "./text".
These elements are stored to a list.
Now we can loop through the list and write each text value to the Report.
Code: Select all
IList<Ranorex.Text> list = repo.Form.Self.Find<Ranorex.Text>("./text");
foreach ( Ranorex.Text textbox in list )
{
Report.Info(textbox.TextValue);
}
More information about the RanoreXPath can be found in the user guide.
Please let me know if you need more information.
Regards,
Johannes
Re: Change C# type of repository item
Damn, took me half the day to find out myself what you posted then with a perfect explaination
. It's not exactly what I was looking for because I don't like hardcoded strings in my sourcecode but it's not too bad.
After that problem got solved the very next question was how to find the nearest item with a certain id. Is there a way to do that? Like jQuery closest https://api.jquery.com/closest/ in Ranorex.

After that problem got solved the very next question was how to find the nearest item with a certain id. Is there a way to do that? Like jQuery closest https://api.jquery.com/closest/ in Ranorex.
Re: Change C# type of repository item
Hi,
You can always replace the hardcoded string with variable and fill that variable from a connected data source. This is definitely better wayhaniball wrote:Damn, took me half the day to find out myself what you posted then with a perfect explaination. It's not exactly what I was looking for because I don't like hardcoded strings in my sourcecode but it's not too bad.

Could you be more specific about what exactly you want to do? Is your next question related to the previously explained Find method or something completely different? Could you please post a Ranorex snapshot showing the requested element and its surrounding elements? With snapshot, it would be easier for us to suggest a solution.haniball wrote:After that problem got solved the very next question was how to find the nearest item with a certain id. Is there a way to do that? Like jQuery closest https://api.jquery.com/closest/ in Ranorex.
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: Change C# type of repository item
You ask if that is related to the find Method. No I am looking for a command like jQuery closest but in Ranorex.
I created a new Post because it's not really related to this one... -> http://www.ranorex.com/forum/find-close ... t8492.html
I created a new Post because it's not really related to this one... -> http://www.ranorex.com/forum/find-close ... t8492.html