As Marlin Jack and others have said, GROUND, GROUNG GROUND. Check all the ground connections from the battery to chassis and chassis to everything else. I had a headlight issue with a limit switch. I would pass the contenuity test but failed to work. Once I replaced it the issue went away.
Ken