简体   繁体   中英

QTP read webtable content

I have a WebTable in QTP like:

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

Here, I want to capture the values divFirst and divData for each divRow, ideally, store every divRow in a string.

Could someone please tell me how can I do that?

Thanks a lot

This seems to work:

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

The reason I'm using descriptive programming with an index that will run out is that ChildObjects does not return these WebElements

(Obviously you will want to do something other than MsgBox with the values.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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