Use xpath instead of looping through the elements