If you notice water in the junction box while working on your home, you should call a licensed electrician. This goes for junction boxes located outside the home, as well as those inside that may be getting wet due to an external leak. The electrician can evaluate the wiring in the box to see if the water has caused any damage or if steps can be taken to prevent further water from entering.
Even when a junction box is located inside the home, the roof is still often the cause of moisture in the box. A small leak in the roof is all that water needs to run down the insides of walls, across ceiling joists and along many other paths that can lead to a junction box. Check the roof for cracks, loose or missing shingles and repair any problems that you find to stop or slow the flow of water to the box.
If water in the junction box is an ongoing problem that other measures don't seem to fix, contact an electrician to replace the boxes with waterproof ones. A waterproof junction box is completely sealed so that water can't find an opening to run into the interior where it could do damage. If you're not comfortable working on electrical systems, this type of work should be done by a professional rather than on your own, as there are certain dangers associated with any electrical work and junction boxes need to be installed according to building codes. If you install the new box yourself, always make sure that the power is turned off before you start working with any wiring.
Instead of installing all new junction boxes, you can also prevent water from running into them by installing a pass-through designed to prevent water transfer. Electrical wires provide a path that moisture can travel through, but by running them through a pass-through designed to stop moisture transfer and prevent condensation, you can eliminate water running into the junction box. Most leaks occur where the wires enter the box, and these pass-through devices seal off that point of entry to keep the wires on the interior dry.