Search code examples
vbscriptqtphp-uft

Check if string exists in HTML table using VbScript


Hi I am new to HPE UFT testing and I'd like to write a VBscript. This is my HTML Table:

 <table class="table table-striped table-condensed data-table dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
   <thead>
      <tr role="row">
         <th tabindex="0" class="sorting" aria-controls="DataTables_Table_0" style="width: 226px;" aria-label="Name: activate to sort column ascending" rowspan="1" colspan="1">Name</th>
         <th tabindex="0" class="sorting" aria-controls="DataTables_Table_0" style="width: 481px;" aria-label="Address: activate to sort column ascending" rowspan="1" colspan="1">Address</th>
         <th tabindex="0" class="sorting" aria-controls="DataTables_Table_0" style="width: 138px;" aria-label="VAT Number: activate to sort column ascending" rowspan="1" colspan="1">VAT Number</th>
         <th class="sorting_disabled" style="width: 64px;" aria-label="&amp;nbsp;" rowspan="1" colspan="1" data-orderable="false">&nbsp;</th>
      </tr>
   </thead>
   <tbody>
      <tr class="odd" role="row">
         <td>myCompany</td>
         <td>test street, USA, WD</td>
         <td>65465465465464</td>
      </tr>
      <tr class="even" role="row">
         <td>Supplier</td>
         <td>Franklin Street, USA, NYC</td>
         <td>654564654654</td>
      </tr>
   </tbody>
</table>

Id like to write a function or procedure to loop through the table and check if the string myCompany does exist in the table body. The test scenario is accepted if the specific Company Name is shown in the result list.


Solution

  •  IntRowNum=Browser("CreationTime:=0").Page("name:=myPage").WebTable("name:=myTable").getRowWithCellText("myCompany")
    

    IntRowNum is -1 if the text is not found. Otherwise the rownumber is returned.