Micro Focus QTP (UFT) Forums
How do I specify an object with a randomly generated name? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How do I specify an object with a randomly generated name? (/Thread-How-do-I-specify-an-object-with-a-randomly-generated-name)



How do I specify an object with a randomly generated name? - RandomGrin - 12-27-2012

Hi,

What I'm trying to do is:

Code:
Dialog("Mywindow,  Provider ID = 762222,  Track ID = AAAA").WinButton("text:=New").Click

The problem is that Track ID is randomly generated each time, so it can not be found in the OR.

Then I read that properties are regular expressions, so I tried:

Code:
Dialog("text:=Mywindow,  Provider ID = 762222,  Track ID = ????").WinButton("text:=New").Click

And it couldn't find that either. (did I do my regexp wrong? Why didn't this work?)

Then I read that RegExpWndTitle is, 'The constant part of the window title.'

So I tried,

Code:
Dialog("RegExpWndTitle := Mywindow,  Provider ID = 762222,  Track ID =").WinButton("text:=New").Click

Because that is the constant part, right?

And that didn't work either. (Why not?)

So is there a way to fix one of my two attempts above, or is there a different method I should be using?

Thanks for any ideas,

Random


RE: How do I specify an object with a randomly generated name? - RandomGrin - 12-28-2012

Just to be clear, the actual name of the window is:

Code:
"Mywindow, Provider ID= 762222, Track ID = AAAA"

including the commas and the '=' signs. It is NOT supposed to be a list of properties, it is just a strange looking window name.

Maybe I should have said that I want to do this:

Code:
Dialog("WindowTitleXXXX").WinButton("text:=New").Click

The problem is that the 'XXXX' part of the name keeps changing.

So......any ideas?

Thanks,
Random


RE: How do I specify an object with a randomly generated name? - RandomGrin - 12-28-2012

AND THE ANSWER IS!!!:

Code:
Dialog("text:=Mywin.*").WinButton("text:=&New").Click
So simple once you get it right!

The reasons this took me forever:
- you can have a space after the :=, but not before it, sometimes I had that wrong.
- ? does not replace a single char as I thought, actually that is '.'
- '.*' does replace any sequence of chars
- I don't know if RegExpWndTitle:= would have done it too, but text:= works, and I'm too tired of experimenting to find out if that was a problem.
- Sometimes I was using :=New, but the actual text was :=&New

Stupid little details can cause so much havoc...this is why I never want to be a programmer again...

Maybe I was talking to myself here...but in case anyone cared I thought I'd post the answer that drove me nuts for 2 days...

Random


RE: How do I specify an object with a randomly generated name? - Ankur - 12-29-2012

This may have worked but a problem may arise when you have some other dialog box starting with the same text "Mywin".
Random generated IDs is a common situation encountered in QTP.

Here is what you should do in such situations-
  1. Try to find out the place where that ID is FIRST occurring in a particular session.
  2. Capture that ID in some variable
  3. Append that variable in your statement above



RE: How do I specify an object with a randomly generated name? - diya - 12-31-2012

thanks for sharing the answer!!!!