Forum Discussion

M_McDonald's avatar
M_McDonald
Super Contributor
15 years ago

Simple way to get Xpath Match expression to return "" instread of "null"?

When I have empty elements in a request response, an XPath expression for that element evaluates to a "null" in an Xpath Match assertion. Where I want that to match an empty string I've been doing

[tt:3eb72vux]if (xpath_exp)
then xpath_exp
else ""[/tt:3eb72vux]

but I wonder if there is a simpler way to do this?

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    I'm not entirely sure what you mean (sorry!), can you show a screenshot or something so I get this "in context"?

    regards!

    /Ole
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK, see attached.

    As you can see in the background, the element is empty. The actual result of the xpath is "null" but the expected result is empty (normally I would have some  property that resolves to an empty string in the Expected Result field.)

    I get around this possibility by using if/then/else

    [tt:1rrfulbt]if(//Results[1]/ResultSet[1]/Row[1]/AGE[1]/text())
    then //Results[1]/ResultSet[1]/Row[1]/AGE[1]/text()
    else ""[/tt:1rrfulbt]

    but I wondered if there was a simpler way to handle this (like a ternary expression) or if an "ifnull" option could be added to cover these situations.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK, for strings at least I found something that seems to work:

    concat(//Results[1]/ResultSet[1]/Row[1]/AGE[1]/text(),"")