Railway dynamics is a multidisciplinary area that involves several fields of research. From a mechanical point of view, the aim is to study the dynamic behaviour of the rail vehicle. In this case, detailed vehicle modelling methodologies are used, generally using the multibody system formulation, while the track is generally considered as a rigid structure or modelled considering that the rails sit on an elastic foundation. On the other hand, from a civil or geotechnical engineering point of view, the purpose is to study the track behaviour in detail. In such case, detailed track models are used considering the rails, pads, sleepers, ballast and subgrade, whereas the vehicle is generally represented by vertical moving loads of constant magnitude. The problem of the railway vehicle dynamics is that the track exhibits flexibility, which has implications on the vehicle's performance and should not be disregarded. In order to give answers to the demands for more accurate and efficient vehicle-track interaction models, a finite element formulation is proposed here to represent the track in which the rails and sleepers are supported in a discrete manner by springs and dampers that represent the physical properties of the track components. For this purpose, a computational tool is developed to build flexible track models in an automatic way. It receives as input the spatial geometry of the track and the properties of the track components. The methodology is fully generic, enabling the consideration of any track geometry and any track characteristics, such as ballast, slab or asphalt tracks. Furthermore, the flexible track models are fully compatible with the multibody tools used to study detailed vehicle models and are numerically efficient, enabling vehicle-track interactions studies along large lengths. The proposed methodology is demonstrated here in realistic operation scenarios and the results are compared with the ones obtained with the conventional approach, i.e., using vertical moving loads representing the vehicle loads.