Batteries are charged using electricity and hydrogen can be made by electrolysis of (passing electricity through) water so both offer the same fuel-independence as stringing up wires above the track.
There's an interesting comparison to be made regarding end-to-end efficiency between the two (and indeed with fixed infrastructure electrification).