繁体   English   中英

在QTP中标识WebTable / WebGrid对象

[英]Identifying an WebTable/WebGrid Object in QTP

我在WebTable(Web Grid)的html中有以下代码。

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

好的,假设您具有这样的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()]")

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

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

请告诉我

暂无
暂无

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

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