Identifying WebTable using object inside the table

Tables inside web pages are implemented without any name or id attributes most of the times. This makes it difficult for Automation engineer to create robust scripts for identifying the Table correctly at run-time. QTP by default uses the “index” ordinal identifier to recognized a WebTable, which is not a reliable method for identifying WebTables

Lets consider the HTML code and it’s preview shown below

HTML Preview

Value 1 Delete
Value 2 Delete

If we add the above table to the Object Repository in QTP it will add it using some index. Assuming the index being used by QTP for this table is 1, when a developer adds any table before this Table the index for our actual table will change. We need to find something which can uniquely identify this table. If we observe closely we will notice that Delete link only comes inside this Table. If we are able to extract the Table which contains the Delete link our job would be done. Looking at the HTML code we will notice that we need to traverse from the Delete link node to the TABLE tag node. This traversal can be done using the DOM of the web page. The code shown below demonstrates how to extract a Table from a object inside it

Using the above code we can extract the table from the Link

Similarly we can create functions to get the Cell or the Row which contains the object. This can be used when we want to click on the Row or on the Cell to do some special action.

The complete source code for current article can be downloaded from below link

  GetWebTableObjects.txt (5.4 KiB, 3,851 hits)

Have questions related to this article? Want to request a new article? Use our forums to post your questions

  1. Suscribe to Email

    Enter your email address:

    Delivered by FeedBurner