This is a migrated thread and some comments may be shown as answers.

How to extract text from <span> within <p>?

1 Answer 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 01 Mar 2017, 11:11 AM

Hi

I have the following markup...

<p>
<span>Some fixed text</span>
<span>Some random text</span>
<span>Some more fixed text</span>
</p>

I would like to extract either Some random text (which will be different every time) or all the inner text from the <p>, whichever's easier.

Is there a way I can do this? I can find the two fixed text spans easily, but can't see how to extract the random text from between them.

Thanks

Mike

 

1 Answer, 1 is accepted

Sort by
0
Nikolay Petrov
Telerik team
answered on 03 Mar 2017, 02:06 PM
Hi Mike,

Once you find the first span element you could find its next sibling with those lines of code:
HtmlSpan trouvableSpan = Find.ByContent<HtmlSpan>("Some fixed text");
 
Element randomSpan = trouvableSpan.BaseElement.GetNextSibling();

Hope this answers your question.

Regards,
Nikolay Petrov
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Michael
Top achievements
Rank 1
Answers by
Nikolay Petrov
Telerik team
Share this question
or