This work presents a novel finite element solution to the problem of scattering from an infinite periodic array of two-dimensional cavities in metallic walls. The finite element formulation is applied inside only one cavity to derive a linear system of equations associated with the nodal field values within the cavity. The surface integral equation employing the quasi-periodic Green's function is applied at the opening of the cavity as a boundary constraint to truncate the computational domain. Effect of the infinite array of cavities is incorporated into the system of the nodal equations by the quasi-periodic Green's function. The method presented here is highly efficient in terms of computing resources, versatile and accurate in comparison to previously published methods. The near and far fields are generated for array of cavities with different dimensions, periodicity, and fillings. The numerical simulation results are in close agreement with methods published earlier.