Replacing an electric water heater's thermostat safely requires disconnecting the power, removing cover plates, removing the old thermostat and carefully installing the new one. When working with an electric water heater, it's important to ensure the power is fully disconnected.
Power can be cut to a water heater by turning off the proper breaker. After the front cover is removed, a non-contact voltage tester can be used to make sure power is truly disconnected, as a mislabeled breaker can lead to dangerous working conditions. Removing a thermometer is fairly simple, but it may be wise to take a picture of the wiring to make sure the new thermometer is properly connected before the unit is powered on again. It's also important to make sure the newly-installed thermostat is flush with the wall it touches, as even a small gap can lead to low temperature ratings, which can cause the water heater to overheat and open the safety valve.
It's important to note that electric water heaters typically have two thermostats, one near the top of the unit and one near the bottom; replacing a functional thermostat won't fix the problem. Almost all water heater thermostats also have a reset button. Pressing it and testing the thermostat again can potentially allow homeowners to avoid time-consuming replacement.