Fix failing tests after changes in the CSS classes.
Replace 'while' with a 'for' loop in order to avoid the occurance of infinite loops in certain cases and to improve the performance.
Add classes to the first and last visible items in the command overflow popup.