This will only look for an element that has the specified text immediately beneath it, so if there's a nested tag inside, it will fail.
the contains text version also has the same problem.
I think the generated xpath should be $x("//[descendant::*[contains (text(), '')]]")