Selenium webdriver 如何获取div中的所有文本

Selenium webdriver 如何获取div中的所有文本,selenium-webdriver,Selenium Webdriver,我想将所有文本存储在数组中,这样我就可以一个接一个地断言每个文本 以下是HTML代码: <div id="dvEditPriceMessagePopupContainer" style="display: block;" class="pad12"> <div id="dvEditPriceMsgHeader"><p><i>The following requirements are needed when entering a price:&l

我想将所有文本存储在数组中,这样我就可以一个接一个地断言每个文本

以下是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>

输入价格时需要满足以下要求:


一,。至少有一个活动的有效联系人

2。添加净尺寸或选择不适用 3.添加总尺寸或选择不适用。选择地板类型

5。卧室必须为0或更多。浴室必须为一个或多个

7。选择市场来源


我尝试了以下操作,但对我不起作用

您可以通过获取元素列表,然后对其进行迭代以获取文本或断言文本来完成此操作

List<WebElement> divs= driver.findElements(By.xpath("//div[@id='dvEditPriceMessagePopupContainer']/div"))
List l1 = new ArrayList();
    for(WebElement e : divs){

      l1.add(e.getText());

    }
List divs=driver.findElements(By.xpath(“//div[@id='dveditpricessagepopupcontainer']/div”))
列表l1=新的ArrayList();
for(WebElement e:divs){
l1.add(e.getText());
}