2010-06-04 97 views
1

我有一个QTP喜欢网表:QTP阅读网表内容

<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存储在一个字符串。

有人能告诉我我该怎么做?

非常感谢

回答

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以外的值来做一些事情。)

+0

谢谢,索引的作品,其实我试图让W ebElements但没有成功,谢谢 – allenzzzxd 2010-06-07 11:20:57

+0

@allen,很高兴帮助。 – Motti 2010-06-07 12:52:20