1
votes

I have the below code in html for a WebTable(Web Grid).

<table width="90%">
  <div class="greybox" style="margin-top:2%;">
    <table class="datagrid" width ="100%">....<table>
  </div>
</table>

I tried providing exactly the same(all) properties in my descriptive programming but the Web Element(DIV) is not being identified by QTP. Is there a unique way to identify this?

Note: The Web page is developed a single page application

Edit:

So I think I have resolved the issue with the below code. There were two Objects being identified without the "Unique Text" if clause. First Object was parent of the DIV object so had to use a "Unique text" from the first object which wouldn't be part of any other object. I am currently trying with different data to see if it's working fine

Browsername = Browser("micClass:=Browser").GetROProperty("name")
Pagename = Browser("micClass:=Browser").Page("micClass:=Page").GetROProperty("name")

Set desc = Description.Create()
desc("micclass").Value = "Webelement"

Set ChildObject=Browser("name:="&BrowserName).Page("name:="&PageName).ChildObjects(desc)

Set Child_Table_Value = nothing

For i=0 to ChildObject.Count-1
  innerhtmlvalue = ChildObject(i).GetRoproperty("innerhtml")
  htmltag = ChildObject(i).GetRoproperty("micclass")

  if(Instr(innerhtmlvalue, "MARGIN-TOP: 2%")<>0) then 
    if(Instr(innerhtmlvalue, "UniqueText")=0) then
      if(Instr(htmltag, "WebElement")<>0) then
        Set Child_Table_Value  = ChildObject(i)
      End If
    End If
  End IF
Next

Set Table_Value = Child_Table_Value.WebTable("html tag:=Table")
2
What were you trying to get, the WebTable? Exactly what identifiers were you trying to use? Are there multiple tables on the page with class "datagrid"? And if not, why the focus on the parent div? - Xiaofu
It's a single page application and there are lots of table available. When I tried using the Object spy, I found none of table is being identified using a unique ID, and when run it's being identified by ordinal identifier and since for different data, some tables appear and some doesn't, the table doesn't necessarily point to the right table I am trying to get values from. SO I had to use above work around to identify the correct table. so far it's working fine - Enthusiastic Learner
It's good that you've found a workaround, but if you provide a clearer picture of the HTML then someone here might be able to provide you with a shorter/less convoluted solution. You might be able to do it in a single XPath statement. Can you provide a snippet of the HTML that includes part of the table and this "unique text" you are referencing? - Xiaofu
Yes thats exactly whats in my initial post if you are talking about just properties. I would like to read the inner table data but there is nothing unique about the table. <table width="90%"> <div class="greybox" style="margin-top:2%;"> <table class="datagrid" width ="100%">....</Table> <div> </table>. The .... lines represents data which are the content of the table. One of the content is the Unique text. I am not allowed to share content of the table since it's a confidential client data - Enthusiastic Learner
Just provide a sample HTML with PII replaced with random words like Lorem Ipsum!? - dmcgill50

2 Answers

1
votes

Ok, so assuming you have an HTML structure something like this:

<table width="90%">
  <tr>
    <td>
      <div class="greybox" style="margin-top:2%;">
        <table class="datagrid" width="100%">
          <tr>
            <td>UniqueText</td>
          </tr>
        </table>
      </div>
    </td>
  </tr>
</table>

...and as per your current solution you can rely on "UniqueText" being present, then you could try the following XPath statement:

(//table[contains(., 'UniqueText')])[last()]

So in QTP/UFT you'd be doing:

Browser("micClass:=Browser").Page("micClass:=Page").WebTable("xpath:=(//table[contains(., 'UniqueText')])[last()]")
0
votes

Try to use like below.(Try to identify the div block using the "class")

Browser("micClass:=Browser").Page("micClass:=Page").Webelement("class:=greybox").Webtable("class:=datagrid")

Please let me know