A finite element solution for electromagnetic scattering from an infinite periodic grating