The very first thing you should do before replacing any switch or outlet is to deactivate power to the circuit. Turn off power at your home’s main electrical panel by finding the appropriate breaker and flip it to the “off” position. If you’re not sure which breaker is which, turn off power to the entire house. Then turn the light switch on to double-check that the circuit is off.
Never trust an inoperable light switch as a sign that the circuit is off.
Make sure the circuit is truly “dead” before touching any wires or terminals. Check for a current again with a high-voltage neon tester before working. Test from the black wires to a grounded metal box or other good ground, then to the white wires. Also, test from the white wires to a ground. Be sure your tester is functioning by first trying it in a live receptacle.
After turning the breaker off, cover it with a piece of electrical tape to ensure that no one will turn it on while you’re working.