A numerical approach is described for the analysis of scattering from dielectric obstacles in a rectangular waveguide. The approach is a combination of the finite-element method and the analytical solution. In order to save computer memory, the substructure method is introduced in the finite-element method. To combine the uniform waveguide region with the finite-element-method region, evanescent modes and propagating modes are considered in the analytical solution. Spurious fields like the spurious solutions generated in the finite-element analysis of three-dimensional eigenvalue problems can appear in the three-dimensional discontinuity problems when the variational expression in terms of three components of the magnetic field is used. To suppress and eliminate the spurious fields, the penalty function method is also introduced. To confirm the validity and usefulness of the approach, numerical examples are shown for a rectangular dielectric scattering obstacle in a waveguide.