Fix - check if element exists

Fix in while loop where element is null when a popup component has been removed.