2010-06-04 7 views
1

J'ai un WebTable dans QTP comme:QTP lire le contenu 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> 

Ici, je veux capturer les valeurs divFirst et divData pour chaque divRow, idéalement, stocker tous les divRow dans une chaîne.

Quelqu'un pourrait me dire comment je peux faire ça?

Merci beaucoup

Répondre

3

Cela semble fonctionner:

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 

La raison pour laquelle j'utilise la programmation descriptive avec un indice qui court est que ChildObjects ne retourne pas ces WebElements

(Évidemment, vous voudrez faire autre chose que MsgBox avec les valeurs.)

+0

Merci, l'index fonctionne, en fait j'essayais d'obtenir W ebElements mais pas réussi, merci – allenzzzxd

+0

@allen, heureux d'aider. – Motti