Selenium XPath merge spans text and find element that contains substring

I have problem creating Selenium query to select specific element from list using XPath.
I’ve tried //li[contains(text(), 'Addressing machine wholesaling')] but seems I need to merge inner spans somehow. Is there any way to do this?

Here is the example of list. I need to select first li element at this case.

<ul aria-labelledby="businessActivitySuggestionsProbableHeader1" class="anzsicList probable">
   <li activity="55" index="0" role="option" class="">
       <span class="matchText">Addressing</span>
       <span class="matchText">machine</span>
       <span class="matchText">wholesaling</span>
   <li activity="4554" index="1" role="option" class="">
       <span class="matchText">Machine</span> manufacturing (including accounting, 
       <span class="matchText">addressing</span>, business, enveloping, letter folding, numbering, photocopying or duplicating)

If it’s impossible maybe there other way to do that rather then using XPath?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This XPath,

//li[normalize-space() = 'Addressing machine wholesaling']

will select your first li element, as requested.

See also

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x