Consider the following source code,
<
Though the top-rated answer is fully working - and the most xpath-ish :), let me add an option I don't see proposed yet - using the Get Webelements keyword. E.g.:
@{locators}= Get Webelements xpath=//div[@id='groupContainer']//li[@class='contactNameItemContainer']//span
${result}= Create List
:FOR ${locator} in @{locators}
\ ${name}= Get Text ${locator}
\ Append To List ${result} ${name}
It'll generate and return a list of all matching elements, on which you just iterate on. It might be a tad faster than xpath's [index] reference because the dom is evaluated once - but don't hold me accountable if that's not fully true :)