These foamy patches, known as "Cuckoo Spit" are produced by the nymphs of froghoppers - sometimes called Spittle Bugs. They spend all day drinking plant sap, and then when they're full up, they blow the excess out of their breathing holes creating lots of tiny bubbles.
The froth helps to protect and conceal the nymphs from predators. If you look inside the froth you'll find the little green nymph which is making all the mess. As it grows it develops its hard outer skeleton and wings and can leave the safety of the froth.