How to find all the span tag inside of an element in selenium python?

Viewed 177
<div id="textelem" class="random">                     
   <span class="a">
       TEXT 1
   </span>                            
   <span>
   <span>TEXT 2 </span>
   </span>
   <span>TEXT 3</span>
</div>


Python: TargetElem = self.wait.until(EC.presence_of_element_located((By.ID, "textelem")))

I want to get all the text inside of span tags of TargetElem element. How can I get all the span elements inside of TargetElem element and loop through them to get a single string of collected text. Thank you.

1 Answers

simply use .text

TargetElem = self.wait.until(EC.presence_of_element_located((By.ID, "textelem")))
print(TargetElem.text)

I do not think that you actually need a loop, since we are passing textelem id of div and all the span tags are inside the div, so .text should work.

Related