Page 1 of 1

Unique application help needed

Posted: Fri Aug 10, 2012 4:13 pm
by annias411
I'm evaluating Ranorex for purchase and I need a little help with using your product with our application.

We use Google web tools as a development framework and the objects are dynamic.

So a checkbox ID'd as 'x-auto-118' on one iteration might be 'x-auto-204' on the next.
Untitled.jpg
Putting the checkbox in the repository does no good because the object ID's change every time the application is run. The label remains the same obviously.

Can someone point me in the right direction as to how I should approach this situation in Ranorex please?

Thank you.

Re: Unique application help needed

Posted: Fri Aug 10, 2012 4:32 pm
by Ciege
Personally, I would write my own code that searches for the for the Label element then finds it's sibling Checkbox...

You can also read about using Relationship Operators within Ranorex here: http://www.ranorex.com/support/user-gui ... ditor.html

Re: Unique application help needed

Posted: Wed Aug 15, 2012 8:58 pm
by annias411
Is there any sample code on how to loop through all the labels?

Re: Unique application help needed

Posted: Wed Aug 15, 2012 10:02 pm
by Ciege

Re: Unique application help needed

Posted: Thu Aug 16, 2012 8:36 pm
by annias411
Thanks Ciege for your help, I'm almost there.

I'm new to XPath, so please forgive my ignorance.

This works, it finds the checkbox I'm looking for.
var cb = webDoc.Find("/dom[@domain=myDomain.net']//div[#'x-auto-119']/label[@innertext='mycheckbox']");

However, I need to search all the "x-auto-n" possibilities. The -119 will change because of dynamic creation of the object. The label remains the same.

This does not. :(
var cb = webDoc.Find("/dom[@domain='myDomain.net']//div['^x']/label[@innertext='mycheckbox']");

I was thinking the ^ attribute would act as a wildcard. Maybe I misunderstood.

Can you help me get over this last hump?

Thanks!

Re: Unique application help needed

Posted: Thu Aug 16, 2012 9:38 pm
by Ciege
See if this helps...
You need to use a Regular Expression within your XPath.

http://www.ranorex.com/support/user-gui ... html#c3294

Re: Unique application help needed

Posted: Fri Aug 17, 2012 8:46 pm
by annias411
Figured it out thanks...
(Again this is allowing me to find dynamic input controls created by javascript, which have changing IDs.)
Maybe someone else will find this of value.

var label = webDoc.FindSingle("/dom[@domain='MyDomain.net']//label[@innertext='"+ controlName+"']");

The controls I'm trying to find have labels that remain constant. So I find the label, then get the parent, then get children of the parent.

var labelElement = (WebElement)label;
WebElement parent = labelElement.Parent;
var checkBoxList = parent.Children;

var checkBoxId = checkBoxList[0];

string _checkBoxId = checkBoxId.Element.GetAttributeValue("Id").ToString();
string chSearchStr = "/dom[@domain='MyDomain.net']//input[#'" + _checkBoxId +"']";
var _cb = webDoc.FindSingle(chSearchStr);
WebElement cb2 = (WebElement)_cb;
cb2.Click();

Single out the checkbox portion of the control. Then click it.

*****************
Edit... bleh... too much code. :D

var labelElement = (WebElement)label;
WebElement parent = labelElement.Parent;
var checkBoxList = parent.Children;

var checkBoxId = checkBoxList[0];
checkBoxId.Click();

Works without having to search again for the control... I already have the checkbox child element of the checkbox control...so just click it.

Re: Unique application help needed

Posted: Fri Aug 17, 2012 8:51 pm
by Ciege
I'm glad you figured it out on your own... I apologize for not "helping" more and giving the code to you, but I'm a firm believer in once you figure out the basics on your own you are a better person (developer) for it!

Good job!