2010-06-04 99 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