我希望将所有文本存储在数组中,以便我可以逐个断言每个文本,
这是HTML代码:
<div id="dvEditPriceMessagePopupContainer" style="display: block;" class="pad12">
<div id="dvEditPriceMsgHeader"><p><i>The following requirements are needed when entering a price:</i></p></div>
<div id="dvEditPriceMessagePopup" class="mgrT12"><br><p>1. There is at least one active valid contact</p><p></p><p>2. Add Net size or select N/A</p><p></p><p>
3. Add Gross size or select N/A</p><p></p><p>4. Select Floor type</p><p></p><p>5. Bedroom must be 0 or more</p><p></p><p>6. Bathroom must be 1 or more</p><p
></p><p>7. Select Market source</p><p></p></div>
<div class="textalgncent mgrT12">
<a onclick="javascript:fb.end();return false;" id="lnkEditPricePopupClose" title="Close" class="BlackBtn" href=
"javascript:__doPostBack('lnkEditPricePopupClose','')">Close</a>
</div>
</div>
我试过以下但不适合我
答案 0 :(得分:1)
您可以通过获取元素列表然后迭代它来获取文本或断言文本来完成此操作。
List<WebElement> divs= driver.findElements(By.xpath("//div[@id='dvEditPriceMessagePopupContainer']/div"))
List l1 = new ArrayList();
for(WebElement e : divs){
l1.add(e.getText());
}