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

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.