Working with dynamically named elements

Ask general questions here.
Posts: 7
Joined: Fri May 04, 2012 9:40 pm

Working with dynamically named elements

Post by xrayspex » Tue Jul 10, 2012 9:55 pm

I am trying to automate a situation where I open a bunch of windows by double clicking on a list, have all the windows open at the same time, and then go through and close each one, one by one.

Each window is being recognized by Ranorex as a form with a close button.
The Xpath is similar to this:
/form[@title='Table\ <dynamic name>\ \blahblah']/titlebar/button[@accessiblename='Close']

So the first window opened might be
/form[@title='Table\ vanilla-32\ \blahblah']/titlebar/button[@accessiblename='Close']
The next could be
/form[@title='Table\ chocolate-5\ \blahblah']/titlebar/button[@accessiblename='Close']
and so on.

These names are coming from a list that is variable, so while the first window opened in test run 1 may be vanilla-32, in test run 2 it could be strawberry-86.

I have this in the Repository:
MyDynamicWindow with Xpath /form[@title~'^Table\ .*\ \blahblah']
ButtonClose with Xpath Base:/titlebar/button[@accessiblename='Close']

I have this in code:

Code: Select all

Dim dynamicWindow As Ranorex.Form = "/form[@title~'^Table\ .*\ \blahblah']"
Dim dynamicWindowCloseButton As Ranorex.Button = "/form[@title~'^Table\ .*\ \blahblah']/titlebar/button[@accessiblename='Close']"

<open window 1 - name pistachio-5>
<open window 2 - name coffee-34>
I expect to see
Element '{Form: pistachio-5}' does exist.
Element '{Form: coffee-34}' does exist.

I get this output:
Element '{Form: pistachio-5}' does exist.
Element '{Form: pistachio-5}' does exist.

It's not recognizing the second window as unique, even though it also matches the dynamicWindow path.

Likewise, if I open 10 windows, and then try to gather all their close buttons using

Code: Select all

Dim closeButtonList As IList(Of Ranorex.Button) = repo.MyDynamicWindow.ButtonCloseInfo.CreateAdapters(Of Ranorex.Button)() 
I only get one button. It closes one window and leaves the other nine. I also tried brute force with closeButtonList.Add(dynamicWindowCloseButton) after each window is opened, but that doesn't close all the windows either.

How do I deal with this? I can't close each window after I open it because all the windows have to be open at the same time.


Posts: 7
Joined: Fri May 04, 2012 9:40 pm

Re: Working with dynamically named elements

Post by xrayspex » Tue Jul 10, 2012 10:15 pm

I also tried doing this after I opened the second window:

Code: Select all

Dim windowList2 As IList(Of Ranorex.Form) = repo.MyDynamicWindow.selfinfo.CreateAdapters(Of Ranorex.Form)()        
For each dWindow as Ranorex.Form in windowList2
I only get validation of a single window.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: Working with dynamically named elements

Post by Support Team » Wed Jul 11, 2012 4:40 pm

Hello Lisa,

You can use the method FindDescendant() in a loop to close all windows.
IList<Form> list = Host.Local.Find<Form>("/form['YourWindowForm']");
foreach(Form btn in list){
Ranorex Support Team