Java 元素中的空文本。getText()
我有以下由Angular生成的html代码:Java 元素中的空文本。getText(),java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,我有以下由Angular生成的html代码: <div class="ag-center-cols-container" ref="eCenterContainer" role="rowgroup" unselectable="on" style="width: 495px; height: 50px;"> <div role="row" row-ind
<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>
但是我得到
null
作为一个值。您知道可能会出现什么问题吗?有时元素的实际文本不会出现在文本属性中,而是进入值属性中
试试这个:
actualText = webElement.getAttribute("text");
if (actualText==null) {
actualText = webElement.getAttribute("value");
}
你在什么上得到零?.getText()调用?或者两者都有?for.getText()看起来好像是因为文本位于我要获取的列表的内部列表中?如何获取列表的内部列表?在与元素交互时,可能元素不可见。使用显式wait
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(//div[@ag-center-cols-container']))
no,这并不能解决问题列表中有多少元素?
actualText = webElement.getAttribute("text");
if (actualText==null) {
actualText = webElement.getAttribute("value");
}