Recommand · June 4, 2021 0

Get Angular table rows data

I want to get Angular table rows data. Full page source: https://pastebin.com/JszeSf8q (I had to cut the beginning because it’s huge). I have this table:

<div class="ag-center-cols-container" ref="eCenterContainer" role="rowgroup" unselectable="on" style="width: 700px; height: 50px;">
   <div role="row" row-index="0" aria-rowindex="2" row-id="0" comp-id="130" class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-position-absolute ag-row-first ag-row-last" aria-selected="false" style="height: 50px; transform: translateY(0px); " aria-label="Press SPACE to select this row.">
      <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="4" comp-id="138" col-id="accessorialExpectedUOMShortName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 100px; left: 600px;  ">m</div>
      <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="1" comp-id="131" col-id="operationCodeName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 300px; left: 0px;  ">Accessorial Charge</div>
      <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="2" comp-id="132" col-id="accessorialExpectedAmount" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 150px; left: 300px;  ">120.00000000</div>
      <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="3" comp-id="133" col-id="accessorialActualAmount" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 150px; left: 450px;  ">110.00000000</div>
   </div>
</div>

I tried this:

WebElement accessorialExpectedUOMShortNameWebElement = driver.findElement(By.xpath("//div[@col-id='accessorialExpectedUOMShortName']"));
        assertEquals(accessorialExpectedUOMShortNameWebElement.getText(), "UOM");

        WebElement operationCodeNameWebElement = driver.findElement(By.xpath("//div[@col-id='operationCodeName']"));
        assertEquals(operationCodeNameWebElement.getText(), "Operation Code");

        WebElement accessorialExpectedAmountWebElement = driver.findElement(By.xpath("//div[@col-id='accessorialExpectedAmount']"));
        assertEquals(accessorialExpectedAmountWebElement.getText(), "Expected");

        WebElement accessorialActualAmountWebElement = driver.findElement(By.xpath("//div[@col-id='accessorialActualAmount']"));
        assertEquals(accessorialActualAmountWebElement.getText(), "Actual");

I get the table labels. Do you know how I can get the table row values?