Expanding foam is applicable in many aspects of do-it-yourself home improvement, from fixing cracks in walls to insulation. It's very easy to use and very good at its job, but as the foam expands it tends to leak and can create lumps or marks on walls. Removing the foam as it's drying is problematic as it will continue to expand, but removing it when it's dry is a relatively simple task.
Cut off as much of the foam as you can with the craft knife. This doesn't need to be extremely accurate but the more you can cut off the better.
Sand the expanding foam with sandpaper so it's flush with the wall.
Wipe over the area with a damp cloth to remove any foam or sandpaper particles.
Paint over the area as required so it blends into the rest of the wall.