I think they use light spectrum to identify different elements. As different chemicals and elements absorbs different wavelength of the light, you end up with lines on certain spot on the spectrum and therefore you can identify what's infront of the light.
Wiki link