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)?
reference to repository elements dinamically
reference to repository elements dinamically
Last edited by BJosef on Wed Nov 02, 2016 4:07 pm, edited 1 time in total.
Re: reference to repository elements dinamically
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: 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.
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']
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.
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: reference to repository elements dinamically
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..
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
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.
/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
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
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