Highlighted
Contributor.
Contributor.
2308 views

UFT 14, approach on how to work with web objects with dynamic html_id

Hello all,

I am trying to work with a  web application (windows 7, 64bit) using UFT 14.00 with Web add in and .Net loaded. I have checked the elements on the web page, via UFT object spy. 

They do not have a 'name' property and the html_id always changes when the page is loaded.

I have checked the elements through web's 'inspect element'. The class name is not unique, there is not html_name and the html_id is dynamic.

What could be the best solution for me to handle such a web application?

 

 

0 Likes
17 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Are the html ids fully dynamic or is there a static piece you can use with a regex?

Mark Smith.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Hello Mark and thanks for the reply.

This is an example of an object's ID:

z_em_6v2
z_gm_k9 - after refreshing the page

The object's class is : 'b-refresh'

The only part of the id that stays the same is : 'z_'

Have any idea over this ?

 

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Hmm I see your dilemna..

Only thing I can think of is using something like:

("html id:=Z.*", "index:=0")

Mark Smith.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Mark, you are correct about this.

This is a dillema since there is no HTML_NAME property (empty) and the developers are in another state of mind(if its working dont touch it...) They are not going to grant each object a html_name...

So the solution you suggested might be the only one that will work.

Problem is if the page loads with many of these objects, how to find the relevant one??

Do you think I can "loop" through all of the present objects and search each one for something more specific like a certain label ?

 

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: UFT 14, approach on how to work with web objects with dynamic html_id

But how will you know during the loop if you have got the correct one?

Mark Smith.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Hmmm.

 

Still thinkg about this.

I would like to ask something more, when I use the GUI spy I have a 

Class Name and a class property...

How would I call 'class name' in a descriptive programming way?

I know that 'class' is defined as 'micclass'.

Please see attached image

Thank-you.

 

 

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

If using descriptive, you may use "micclass=z-label". If the innertext value is stable you may even use that as a locating property.

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Typo - You forgot the colon

"micclass:=z-label"

Please note the class property and class name can be different (especially for WebElements which is a default class name for lots of objects)

When using class name, it is implied by the object identifier e.g. .WebCheckBox("X") Sometimes you need to use more than 1 property to uniquely identify an object like when there is a Continue button at both the top and bottom of a page. Here you would use the following:

' Click the top button
.WebButton("Name:=Continue","index:=0").Click

' Click the bottom button
.WebButton("Name:=Continue","index:=1").Click

You do not say what kind of object you are trying to interact so in the example I will assume its a WebButton, you will want to do something like:

.WebButton("html id:=z_.*","Class:=b-refresh").Click

Mark Smith

 

 

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

Thank-you for the replies.

Mark, when you are using this notation:

.WebButton("html id:=z_.*","Class:=b-refresh").Click

What you actually do, is "create" an object on the fly, right? Without having to go through 'Description.Create' like:
    Set ObjLbl = Description.Create
    ObjLbl("micclass").value     = "WebElement"
    ObjLbl("class").value         = "b-label-s b-pointer"
    ObjLbl("html tag").value     = "SPAN"

ObjLbl.Click

 

Am I correct here?

 

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: UFT 14, approach on how to work with web objects with dynamic html_id

This does not creat an object as it does not use the Set command.

Does this approach work on your dynamic objects?

Mark.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: UFT 14, approach on how to work with web objects with dynamic html_id

I am sorry , but I dont understand.

i create the object using the refular SET command as such:

Set ObjDevice = Description.Create
ObjDevice("micclass").value     = "WebElement"
ObjDevice("class").value         = "z-label"
ObjDevice("html tag").value     = "SPAN"

 

Am I missing something here ?

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.