E4X is namespace aware, so to access the element that is in a non-Default namespace you either need to declare the namespace/prefix or use a wildcard *.
Edit: Some debugging in the ESB itself showed me that we cannot use the word "return". This is a reserved word, and is not allowed, not even as part of the query string to retrieve the "return" element from your xml.
Lets assume for a moment that the element was called "value" instead, then the code would compile and work as follows:
var ns = new Namespace('http://main.wsmediator');
var xmlValue = mc.getPayloadXML()..ns::value.toString();
Another option is to use the wildcard:
var return = mc.getPayloadXML()..*::value.toString();
However changing the xml payload to adhere to JavaScript standards is not a very pretty, and possibly not a viable solution. Instead we can to try to acces the element in another way.
<inSequence>
<script language="js">
var ns = new Namespace('http://main.wsmediator');
var value = mc.getPayloadXML().*.toString();
mc.setProperty("Asterisk", value);
</script>
<log>
<property name="Asterisk" expression="get-
property('Asterisk')"/>
</log>
<respond/>
</inSequence>
The getTestMethodResponse element is the root element when you do mc.getPayloadXML(), the asterisk gives you the children of this element. This works, yet is not very pretty because it is based on some assumptions about the message structure.
Another option might be to completely forego using the script mediator and use a PayloadFactory instead. For example:
<payloadFactory media-type="json">
<format>
{"return":"$1"}
</format>
<args>
<arg xmlns:ns="http://main.wsmediator"
evaluator="xml"
expression="//ns:return"/>
</args>
</payloadFactory>
For more on E4X, check here
For more on PayloadFactoryMediator check here