Page 1 of 1

Change C# type of repository item

Posted: Fri Sep 18, 2015 2:32 pm
by haniball
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?

Re: Change C# type of repository item

Posted: Fri Sep 18, 2015 5:07 pm
by krstcs
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/

Re: Change C# type of repository item

Posted: Fri Sep 18, 2015 9:55 pm
by haniball
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...

Re: Change C# type of repository item

Posted: Mon Sep 21, 2015 3:42 pm
by krstcs
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.

Re: Change C# type of repository item

Posted: Mon Sep 21, 2015 3:54 pm
by Support Team
Hello haniball,

Below you can find a sample, which shows one way to use the Find()-method.

Code: Select all

public IList<Element> Find(
	RxPath path
)
In my sample I'm using a simple form, which contains three text boxes.
form.png
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);
}
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

Re: Change C# type of repository item

Posted: Mon Sep 21, 2015 10:57 pm
by haniball
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.

Re: Change C# type of repository item

Posted: Tue Sep 22, 2015 7:44 am
by odklizec
Hi,
haniball 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.
You can always replace the hardcoded string with variable and fill that variable from a connected data source. This is definitely better way ;)
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.
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.

Re: Change C# type of repository item

Posted: Tue Sep 22, 2015 11:17 am
by haniball
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