Forum Discussion

jon_yates's avatar
jon_yates
Occasional Contributor
11 years ago

Testing for NULL

Hi all,



With the following line (an error message), how do you test to see if anything was found:



var text = page["NativeWebObject"]["Find"]("contentText", "The Name already*", "span"); 



Thanks all





  • Hi Jon,



    You need to check the Exists property of the returned object. If nothing was found, the result is a "stub" object with Exists=false:



    if (text.Exists) {

      // Found

    }

    else {

      // Not found

    }

  • jon_yates's avatar
    jon_yates
    Occasional Contributor
    Hi.



    That's the code I've been trying. It always returns false, even when the text is visible?



    Jon
  • Could it be that contentText is multiline, with a line break (code 10, \n) somewhere between the words? That's how contentText combines the text of child tags – it uses line breaks rather than spaces. Check how the contentText value appears in the Object Browser.