Forum Discussion

Nilam's avatar
Nilam
Occasional Contributor
7 years ago

You are trying to call the "Click" method or property of the "item" object that does not exist.

You are trying to call the "Click" method or property of the "item" object that does not exist. This additional information comes when i search a web element using "page.NativeWebObject" and also in some case when i search by using X path , i got the same problem in test log like object doesn't exist. what is it mean and how can i solve it.

 
  • Hi,

     

    Basically, The error message says the object you are trying to Click is not exists in your page.

     

    Always good to check exists then do the operation as like below,

     

    function clickObject(){
          var pageObject = page.FindChildByXpath("<your xpath>");
          
          if(pageObject.Exists){
                pageObject.Click();
          }else{
                Log.Error("Object not exists on the screen");
          }
          //Or you can use the CheckProperty which is in-build function
          https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.html      
    }

     

     

     

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    Basically, The error message says the object you are trying to Click is not exists in your page.

     

    Always good to check exists then do the operation as like below,

     

    function clickObject(){
          var pageObject = page.FindChildByXpath("<your xpath>");
          
          if(pageObject.Exists){
                pageObject.Click();
          }else{
                Log.Error("Object not exists on the screen");
          }
          //Or you can use the CheckProperty which is in-build function
          https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.html      
    }

     

     

     

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      My $0.02 to the explanation given by shankar_r:

      -- When searching by XPath, TestComplete tries to match the found native DOM element(s) to the objects from its (TestComplete's) objects tree;

      -- If the match succeeds, TestComplete's object is returned. Native DOM element is returned otherwise;

      -- If XPath found nothing then null is returned (see TestComplete's documentation for more details).

       

      So, if TestComplete was able to match the found DOM element to its objects tree, you will be able to call .Click() method because this is a method that TestComplete adds to all UI objects from its object tree.

      If TestComplete failed to match the found DOM element to its objects tree and the native DOM element was returned, you will be able to call .Click() method only if it is supported by this given DOM element. And the chances are high that the call will fail because of case-sensitivity: .click(), but not .Click() is usually supported by DOM elements.

      If XPath found nothing, it is obvious that the call to null.Click() will fail as well.

       

      P.S. The above is one of the reasons why XPath search is highly not recommended for TestComplete.

       

      P.P.S.

      var pageObject = page.FindChildByXpath("<your xpath>");
      if(pageObject.Exists
        ...

      Note, that the above verification will work as expected only if TestComplete can match the found DOM element to its object. If not, then you will get an error that .Exists property does not exist (which is correct, because native DOM element does not contain .Exists property).
      So, if you really need to search by XPath, you must check for null first to ensure that something was found, then check if .Exists property is supported. If it is, then you may assume that TestComplete's wrapping object was returned and can use any method provided by TestComplete. Otherwise, you can use only native web methods provided by this given found DOM element.

       

      (This is another reason why XPath is not recommended for TestComplete :) )

      • shankar_r's avatar
        shankar_r
        Community Hero

        This is obvious AlexKaras, I haven't worked much with Web testing and TestComplete hence i missed that point to make it. Thanks for updating that too. :smileyhappy: