Page 1 of 1

reference to repository elements dinamically

Posted: Mon Oct 31, 2016 5:06 pm
by BJosef
Hi,
I have the following question.

I'd like to refer to some repository elements dinamically.

For example, I have a button.

Let's say it is a delete button.

It's name is constructed  like this:
suppose I want to delete an element called "Joe"
In this case the delete button is called in Spy:

Joe.DeleteButton

In case of Bill, it is called

Bill.DeleteButton

If I want to implement a click on it I'd like to use a statement like this:

repo.Joe.DeleteButton.Click();
repo.Bill.DeleteButton.Click();

But the name is determined during runtime.

Can I set , construct this repo....  statement dinamically or is there a way torefer dinamically (during runtime)?

Re: reference to repository elements dinamically

Posted: Mon Oct 31, 2016 5:50 pm
by odklizec
Hi,

Could you please post a Ranorex snapshot of the element(s) in question? Or at least the xpath for both elements? Basically, it does not make much sense to make the repo structure dynamical, nor I'm aware of any possibility to do so. What you are looking for is making the xpaths dynamical. Let's say there is a "name" attribute for each button, which contains value like Joe.DeleteButton or Bill.DeleteButton.
So all you need is to create a repo item "DeleteButton", with the end of xpath like this:

Code: Select all

//button[@name~'\.DeleteButton']
This xpath should match both delete buttons. Exact xpath depends of the available attributes and your GUI structure. This is why I've asked for Ranorex snapshot.

In case both (or more) delete buttons are visible in GUI at the same time, you will most probably have to handle them via some kind of coded loop and a repository variable, which should be filled with exact name (Joe, Bill, etc.) during each loop iteration. But it's just my wild guess :) Without the GUI snapshot, it's really hard to suggest something reliable. So please, post the snapshot (not screenshot!). Thanks.

Re: reference to repository elements dinamically

Posted: Wed Nov 02, 2016 4:12 pm
by BJosef
Hi,

the xpath looks like these


/form[@title='Delete: Joe']//button[@text='&Finish']

/form[@title='Delete: Bill']//button[@text='&Finish']

/form[@title='Delete: Tom']//button[@text='&Finish']


And in my Ranorex user code module I'd like to refer to one of these.
Joe, Bill, Tom are nodes of a tree - and if I click to Joe then Delete button of Joe should activated
If I click to Bill then Delete button of Bill should activated... etc

Something like this:

repo.Joe_DeleteButton.Click();

But instead of Joe_DeleteButton a dinamically usable button should be activated.

"Are you sure you want to delete the node Joe?"

Something like this..

Re: reference to repository elements dinamically

Posted: Wed Nov 02, 2016 6:31 pm
by tvu
You can add a variable into the Xpath that represents the name:
/form[@title='Delete: ' + $nameOfPerson + '']//button[@text='&Finish']
or
/form[@title~$nameOfPerson]//button[@text='&Finish']

Then in your code, you would do something like this:
repo.nameOfPerson = "Joe";
repo.DeleteButton.Click();

If you are using a recording then adding the repo item will automatically add $nameOfPerson as a recording parameter. Then you don't have to do repo.nameOfPerson = "Joe" in your code.

Re: reference to repository elements dinamically

Posted: Wed Nov 02, 2016 7:19 pm
by BJosef
Hi,

tvu , yes I I need such an implementation.

I use C# , not recording - I will use something similar you wrote in your reply.

Thanks for the idea :-)