简体   繁体   English

在QTP中标识WebTable / WebGrid对象

[英]Identifying an WebTable/WebGrid Object in QTP

I have the below code in html for a WebTable(Web Grid). 我在WebTable(Web Grid)的html中有以下代码。

<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. 我尝试在描述性编程中提供完全相同的(所有)属性,但是QTP不能识别Web元素(DIV)。 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. 有两个没有“唯一文本” if子句的对象。 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. 第一个对象是DIV对象的父对象,因此必须使用第一个对象中的“唯一文本”,该文本不会成为任何其他对象的一部分。 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")

Ok, so assuming you have an HTML structure something like this: 好的,假设您具有这样的HTML结构:

<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: ...并且根据您当前的解决方案,您可以依靠存在的“ UniqueText”,然后可以尝试以下XPath语句:

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

So in QTP/UFT you'd be doing: 因此,在QTP / UFT中,您将执行以下操作:

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

Try to use like below.(Try to identify the div block using the "class") 尝试如下使用。(尝试使用“类”标识div块)

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

Please let me know 请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM