Sujit Soni
Sujit Soni

Reputation: 135

How to get all text inside div

i wanted to get all text store in array so that i can assert each text one by one ,

Here is HTML code :

<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>

I tried following but does not work for me

Upvotes: 1

Views: 1578

Answers (1)

Bhumi Panchal
Bhumi Panchal

Reputation: 69

You can do this by getting list of elements and then iterate it to get text or assert text.

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

      l1.add(e.getText());

    }

Upvotes: 1

Related Questions