1

我在 html 中有以下代码用于 WebTable(Web 网格)。

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

我尝试在我的描述性编程中提供完全相同的(所有)属性,但 QTP 没有识别 Web 元素(DIV)。有没有一种独特的方法来识别这个?

注:网页为单页应用开发

编辑:

所以我想我已经用下面的代码解决了这个问题。在没有“唯一文本”if 子句的情况下标识了两个对象。第一个对象是 DIV 对象的父对象,因此必须使用第一个对象的“唯一文本”,该对象不属于任何其他对象。我目前正在尝试使用不同的数据来查看它是否工作正常

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")
4

2 回答 2

1

好的,假设你有一个类似这样的 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>

...并且根据您当前的解决方案,您可以依赖存在的“UniqueText”,然后您可以尝试以下 XPath 语句:

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

所以在 QTP/UFT 你会做:

Browser("micClass:=Browser").Page("micClass:=Page").WebTable("xpath:=(//table[contains(., 'UniqueText')])[last()]")
于 2014-01-27T04:31:43.860 回答
0

尝试使用如下。(尝试使用“类”来识别 div 块)

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

请告诉我

于 2014-01-27T05:21:54.610 回答