Micro Focus QTP (UFT) Forums
How to identify object once it is moved on the page - 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 to identify object once it is moved on the page (/Thread-How-to-identify-object-once-it-is-moved-on-the-page)



How to identify object once it is moved on the page - thakkarbhav - 10-01-2009

Hello,

I have web page where we display different books on the selected topic. Our sales department update this list once a month and post new book on the top. Now I have recorded script last month where I am clicking on first book on first row and then doing some comaprision.

My script FAILES because now First book on first row is changed. My Original book is now in the second row.

How can i idenfity the object once it is moved on the page?

Regards,
Bhavesh


RE: How to identify object once it is moved on the page - Saket - 10-02-2009

You can use descriptive programming to identify the books dynamically. search this forum for more help on DP.


RE: How to identify object once it is moved on the page - jsknight1969 - 10-02-2009

I found the best way was to add the HTML ID property to the object in the repository. Obviously provided it has a tag. This allows you to always find the object anywhere on the page provided the id is unique. I sometimes had to add it manually by doing a "view source" on the page. This can be tricky if it's a .NET web page, but so far with a little effort, I've been pretty successful at making it work.


RE: How to identify object once it is moved on the page - thakkarbhav - 10-02-2009

How to add HTML ID Property in the OR?


RE: How to identify object once it is moved on the page - jsknight1969 - 10-02-2009

In the repository, select the object. On the right you should see the object properties area. In that area is a green +. click that and you will get a properties dialog popup. Depending on the class of object, you will see properties you can add. HTML ID should be one of them if it s a properly identified web object. There might be other tags you can use in there if ID isn't available. Be careful with X,Y as your control is moving around.


RE: How to identify object once it is moved on the page - thakkarbhav - 10-02-2009

That is fine. so what can i do after finding the HTML Id? I have to use DP to find the ID and then click on that link so that If link (Object) is moved then I will ok?

Thanks,
Bhavesh


RE: How to identify object once it is moved on the page - jsknight1969 - 10-02-2009

Yep. Just call the object with the action....

Browser(something).Page(page).object(name).whatever.

All the HTML id will do is allow you to find the object on the page. It's a unique identifier for the object.

you can now iterate throught the rows and cell once the tableobject is uniquely identified like so:

Code:
For x =2 to Browser(browserobject).Page(pageobject).WebTable(tableobject).RowCount
y = y + cdbl(trim(replace(Browser("browserobject").Page("pageobject").WebTable("tableobject").GetCellData(x, 4),"$","")))
next

This example would sum dollar amounts in each row column 4


RE: How to identify object once it is moved on the page - Ankur - 10-03-2009

In case the books is inside the web table. Here is what you can do to make your script generic:

  1. Get the total number of rows of a web table.
  2. Using conditional statements (comparing every cell name with the book name) narrow down the cell.
  3. Now using WebTable().ChildItem property click on the book name.



RE: How to identify object once it is moved on the page - jsknight1969 - 10-03-2009

yep.

You can also use the GetRowWithCellText()

like....

Code:
x=  Browser("MSN").Page("MSN").WebTable("LinkTable").GetRowWithCellText("CNN",1)
Browser("MSN").Page("MSN").WebTable("LinkTable").ChildItem(x,1,"Link",0).Click

This code would look for "CNN" in column 1, then click the link in the row.


RE: How to identify object once it is moved on the page - Ankur - 10-03-2009

Yes, that will also work but make sure that there is no other entry in the web table that starts with the same name. I have made a post on this topic earlier in one of the threads on How to record the double click actions?