QTP阅读网表内容

时间:2010-06-04 11:58:44

标签: vbscript qtp

我在QTP中有一个WebTable,如:

<TBODY>
  <TR></TR>
  <TR>
    <TD>
      <TABLE>
        <TR>
          <TD>
            <DIV class=divRow id=divRow_d_0>
              <DIV class=divFirst>1</DIV>
              <DIV class=divData>toto</DIV>
              <DIV class=divData>fofo</DIV>
            </DIV>
            <DIV class = divRow id=divRow_d_1>
              <!--same structure here-->
            </DIV>
          </TD>
        </TR>
      </TABLE>
    </TD>
  </TR>
  <TR></TR>
</TBODY>

在这里,我想为每个divRow捕获值divFirst和divData,理想情况下,将每个divRow存储在一个字符串中。

有人可以告诉我该怎么做?

非常感谢

1 个答案:

答案 0 :(得分:3)

这似乎有效:

Set RowDesc = Description.Create()
RowDesc("class").Value = "divRow"
RowDesc("index").Value = 0

Set DataDesc = Description.Create()
DataDesc("class").Value = "divData"

While Browser("Browser").Page("Page").WebElement(RowDesc).Exist(1)
    Set Row  = Browser("Browser").Page("Page").WebElement(RowDesc)
    RowDesc("index").Value = RowDesc("index").Value  + 1
    MsgBox Row.WebElement("class:=divFirst").GetROProperty("innertext")
    DataDesc("index").Value = 0

    While Row.WebElement(DataDesc).Exist(1)
        Set Datum = Row.WebElement(DataDesc)
        MsgBox Datum.GetROProperty("innertext")
        DataDesc("index").Value = DataDesc("index").Value + 1
    Wend
Wend

我使用带有索引的描述性编程的原因是ChildObjects不会返回这些WebElements

(显然你会想要使用值来做除MsgBox之外的其他事情。)