I'm assuming that you're not talking about sealing off hazardous areas, so 300.50(E) calls for the conduit to be sealed with an 'identified compound' ... 'or it shall be so arranged to prevent moisture from contacting live parts.
Chapter 1 defines identified as "Recognizable as suitable for thespecific purpose, function, use, environment, application, and so forth where described in particular Code requirement."
My intrepretation would be no that you can not because expanding foam does not make a watertight seal. I know that underground conduits are never water tight, but the intent of the code is to prevent moisture ....
What do othes think?