A finite element code based on the level set method is developed for performing two and three dimensional direct numerical simulations (DNS) of viscoelastic two-phase flow problems. The Oldroyd-B constitutive equation is used to model the viscoelastic liquid and both transient and steady state shapes of bubbles in viscoelastic buoyancy driven flows are studied. The influence of the governing dimensionless parameters, namely the Capillary number (Ca), the Deborah Number (De) and the polymer concentration parameter c, on the deformation of the bubble is also analyzed. Our simulations demonstrate that the rise velocity oscillates before reaching a steady value. The shape of the bubble, the magnitude of velocity overshoot and the amount of damping depend mainly on the parameter c and the bubble radius. Simulations also show that there is a critical bubble volume at which there is a sharp increase in the bubble terminal velocity as the increasing bubble volume increases, similar to the behavior observed in experiments. The structure of the wake of a bubble rising in a Newtonian fluid is strikingly different from that of a bubble rising in a viscoelastic fluid. In addition to the two recirculation zones at the equator of the bubble rising in a Newtonian fluid, two more recirculation zones exist in the wake of a bubble rising in viscoelastic fluids which influence the shape of a rising bubble. Interestingly, the direction of motion of the fluid a short distance below the trailing edge of a bubble rising in a viscoelastic fluid is in the opposite direction to the direction of the motion of the bubble, thus creating a "negative wake". In this paper, the velocity field in the wake of the bubble, the effect of the parameters on the velocity field and their influence on the shape of the bubble are also investigated.