1

I have this html code produced by Angular:

<div class="ag-center-cols-container" ref="eCenterContainer" role="rowgroup" unselectable="on" style="width: 495px; height: 50px;">
   <div role="row" row-index="0" aria-rowindex="2" row-id="1" comp-id="139" class="ag-row ag-row-no-focus ag-row-level-0 ag-row-position-absolute ag-row-even 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="1" comp-id="140" col-id="rowCheckbox" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 32px; left: 0px;  ">
         <mobileweb-checkbox-selection-renderer _nghost-vsa-c15="" class="ng-star-inserted"><i _ngcontent-vsa-c15="" class="fas fa-check" hidden=""></i></mobileweb-checkbox-selection-renderer>
      </div>
      <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="3" comp-id="141" col-id="caption" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 463px; left: 32px; overflow-wrap: break-word;">Testing</div>
   </div>
</div>

I want to get the text into div elements. I tried this:

WebElement tableContainer = driver.findElement(By.xpath("//div[@class='ag-center-cols-container']"));

        List<WebElement> list = tableContainer.findElements(By.xpath(".//*"));


        // check for list elements and print all found elements
        if(!list.isEmpty())
        {
            for (WebElement element : list)
            {
                System.out.println("Found inner innerHTML " + element.getAttribute("innerHTML"));
                System.out.println("Found inner getText " + element.getText());
            }
        }

But I get null as a value. Do you know what might be the issue?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

0

Sometimes the actual text of an element doesn't appear in a text attribute, it goes into the value attribute.

try this:

 actualText = webElement.getAttribute("text");
 if (actualText==null) {
 actualText = webElement.getAttribute("value");
 }
Tal Angel
  • 1,301
  • 3
  • 29
  • 63