The interaction between the rolling stock and the infrastructure plays a crucial role in railway vehicle dynamics. The standard approach consists of using a multibody formulation to model the railway vehicles running on simplified tracks. The track model can be rigid, if it comprises only a geometric description of the rail; semi-rigid, if it considers an elastic foundation underneath the rail; or a moving track model, if it comprises a track section underneath each wheelset traveling with the same speed of the vehicle. Despite their computational inexpensiveness, these approaches do not provide a complete representation of track flexibility and disregard coupling effects with the vehicle and among the track components. This work proposes a methodology to automatically generate finite element models of railway tracks comprising its relevant flexible components, i.e., rails, pads, fastening systems, sleepers, and ballast or slab. The finite element mesh is generated based on a parametric description of the track that allows an accurate description of its geometry, including curvature, cross-level, grade, and irregularities. The methodology is demonstrated with a case study in which a track with a complex geometry is loaded with two different approaches. The first approach prescribes moving loads, which is a typical approach used to design or analyze the infrastructure. The second approach applies loads retrieved from the dynamic analysis of a complete vehicle. The results show the benefits of this method and reveal that prescribed loading underestimates the forces resulting from the vehicle dynamics, which is an important issue on curved sections.