Divergence-free shape functions are proposed for the finite elements, with which inhomogeneously-loaded and arbitrarily-shaped waveguides are analysed. The method is based on vectorial finite element formulation employing edge elements. The shape functions used for the approximation of the fields are shown analytically to be divergence-free and as an evidence, the non-physical solutions that appeared in the longitudinal component finite element formulation have been shown to be absent. To show the validity of the elements, application is made for the analysis of rectangular waveguides loaded with dielectric slab and a waveguide with curved structure. The solutions obtained are compared with the analytical ones or the solutions reported elsewhere. The degree of accuracy has been found satisfactory.