The flow of inviscid bubbles and viscous drops in capillary tubes has been simulated by a Galerkin finite element method with surface tension included at the bubble/liquid interface. The results show good agreement with published experimental results. At low capillary numbers the front and the rear of the bubble are nearly spherical. As the capillary number increases the thickness of the wetting film between the tube wall and the bubble increases, and the bubble assumes a more slender shape with a characteristic bump at the rear. Recirculations are found in front and behind the bubble, which disappear at high capillary numbers. Furthermore the flow of a viscous drop through a doughnut shaped constriction in a capillary tube has been simulated. The simulations show that snap-off may be initiated by a sudden drop in the flow rate after the drops have protruded for some distance beyond the throat and the snap-off time increases with increasing capillary number. Snap-off without a sudden decrease of the flow rate does not seem to occur in constrictions of circular cross section.