Forum Discussion

shane_manjunath's avatar
shane_manjunath
Occasional Contributor
8 years ago

how to check if the object attribute value is NOT NULL

In my test script i have a object period_name which has multiple Item.I just want to fetch the textContent of these items

 

period_name.Item(k).textContent

 

However when running the test case i have noticed sometimes it returns the error that the object is NULL

 

I want to be able to check if the object attribute has a value or not before using it as follows:-

 

do {
                Indicator.PushText("Period Name is NULL")
     }while ( Check to see if object is still NULL)

 

var prd_name = period_name.Item(k).textContent

3 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    You have not given any specific type of object that you want to check. But,

     

    you can check using below stuff, yourObject will be period_name.Item(k)

     

    do {
                    Indicator.PushText("Period Name is NULL")
         }while (yourObject != null)

     

    • shane_manjunath's avatar
      shane_manjunath
      Occasional Contributor

      Thanks shankar and any idea how to check if attribute value is NULL or NOT?

       

      var period = Aliases.browser.FindChild("Name", 'Panel("tabPeriod")', 99);

      var period_name = period.getElementsByClassName("dxtc-link");

       

      period_name.Item(k).textContent

       

      textContent is the attribute here

      • shankar_r's avatar
        shankar_r
        Community Hero

        Hi,

         

        It's pretty simple,

         

        function test()
        {
            var period = Aliases.browser.FindChild("Name", 'Panel("tabPeriod")', 99);
            var period_name = period.getElementsByClassName("dxtc-link");
         
            do
           { //blah blah}while(    period_name.Item(k) != null)
        
           if(period_name.Item(k).textContent != null)
           {
              Log.Message("It is not null")
           }
          else
          {
              Log.Error('It is null")
           }
        }