Page 1 of 1

Identify elements not in repository

Posted: Thu Oct 19, 2017 8:12 pm
by MikeMitchell
Longtime UFT developer and new to Ranorex.

I've recorded of a small script that will add a segment, click a link and fill out some drop downs on a web page. In the repository are the objects captured from that recording. However, I intend the script to be much larger as I will add segments and click similar links, etc...essentially repeating the pre-recorded script but clicking on links and boxes that are created on the fly at different points on the page. These newer objects differ slightly by their ID.

I would rather not record the entire script and add all objects to the repository one by one. Instead I would like to perform all new object identification and interaction dynamically via C# code. I know what the names of the IDs are going to be. However, I'm having trouble identifying these controls because I'm unable to construct the appropriate code to accomplish this. I've searched the forums and Google extensively and cannot seem to capture the correct syntax for this task.

Attached is the snapshot of the dom. The controls in question have the ID of:

ctl00_phMain_lvSegments_ctrl0_fieldUI_lvField_ctrl0_btnEdit <-- this is the only one in the repository, the following will be new:
ctl00_phMain_lvSegments_ctrl1_fieldUI_lvField_ctrl0_btnEdit
ctl00_phMain_lvSegments_ctrl2_fieldUI_lvField_ctrl0_btnEdit

I'm familiar with GetElementById() and am looking for similar functions or snippets to identify elements.

Thanks.

Ranorex 6.1.0
Win7 SP1

Re: Identify elements not in repository

Posted: Thu Oct 19, 2017 9:44 pm
by krstcs
The easiest way to do what you want is to start with the repository object ("repo"), get the dom object and then do a "Find<T>(RxPath pathFromDom)".

Code: Select all

ButtonTag myButton = repo.MyDom.Self.Find<ButtonTag>("//buttontag[@id='MyButtonId']")[0];  //you can use "//buttontag[#'MyButtonId']" if the id is unique
Note that Ranorex uses their own special version of XPath, which is very powerful, but you must always use it, unlike Selenium where you can just identify by id. Ranorex does that, but you have to do it through the RxPath like above.

Re: Identify elements not in repository

Posted: Fri Oct 20, 2017 12:48 pm
by Vaughan.Douglas
I want to reiterate krstcs, using an object repository or similar is simply best practice for any automation effort. It allows you to keep your AUT objects organized (although the Ranorex implementation could be improved upon).

I agree that recording each step is not optimal, and in your situation you shouldn't need to do it. In your object repository you can just create a new objects, give it a name, and toss in the RxPath.

Using a hybrid method, such as you're asking about, can be troublesome when it comes to maintenance. Now you have some objects in the repository and others buried in code. The object repository adds a layer of abstraction that makes changes in the AUT easier to manage. Conversely you can go without the object repository completely, but I wouldn't recommend that route as it just ignores a powerful Ranorex feature. At that point you may as well just use selenium (NTTAWWT).

Re: Identify elements not in repository

Posted: Fri Oct 20, 2017 2:18 pm
by krstcs
Yeah, I have to agree with Doug, you should really consider using the object repository and Ranorex framework as it is. It may seem to make the initial work take longer, but in the long run it will make maintenance much easier. My original post was meant to point you in the direction of what you specifically asked about. :D

Re: Identify elements not in repository

Posted: Mon Oct 23, 2017 12:24 pm
by MikeMitchell
Thanks to both krstcs and Doug - your explanations make total sense. I appreciate the detail and justification. I'll give it a try and post back.

Re: Identify elements not in repository

Posted: Fri Nov 03, 2017 6:35 pm
by MikeMitchell
Just wanted to reply back that the code example above while it worked, it was awfully slow to execute. It allowed me to code without adding a ton of objects to the repository. Eventually I gave in and added everything to the repository and determined that it wasn't half bad. Compared to other tools it's quite pain-free to add and manage. And having the ability to search on an object and be told whether it's being used is a plus to keeping the repo clean. Thanks to all for your help.

Re: Identify elements not in repository

Posted: Fri Nov 10, 2017 12:59 pm
by Vaughan.Douglas
MikeMitchell wrote:Just wanted to reply back that the code example above while it worked, it was awfully slow to execute. It allowed me to code without adding a ton of objects to the repository. Eventually I gave in and added everything to the repository and determined that it wasn't half bad. Compared to other tools it's quite pain-free to add and manage. And having the ability to search on an object and be told whether it's being used is a plus to keeping the repo clean. Thanks to all for your help.
I'm glad you've found something that works! After several years of bending things to my will, I've learned that one should always take advantage of a products builtin utility before trying to customize everything. Even with Ranorex I had to learn the hard way. My first solution was all custom code. Sure it worked, but no one else could maintain it and their eyes would gloss over whenever I try to explain anything. Eventually I went back and put everything into recorded modules and handed it off.

I still customize my RxPath though. The object recorder produces less than elegant results.