Forum Discussion

vibin's avatar
vibin
New Contributor
5 years ago

Wait for Xpath

Hi, I am using test complete for web testing and preferred XPATH to find elements. But I couldnt find a proper wait statement for xpath other than hard coded wait statements. My scripts are failing ...
  • AlexKaras's avatar
    AlexKaras
    5 years ago

    vibin :

    Hi,

     

    I expect a true or false in the variable val

    Your expectation is partially correct.

    Please carefully read for details the documentation for the FindChildByXPath method.

     

    The case is that been a wrapper around native (I guess) XPath search, this method differs from all other FindXXX and WaitXXX methods provided by TestComplete.

    All other methods return found object if succeeded and empty stub one in case of failure. Returned stub object contains the only property Exists and verification like in your code is correct for these cases.

    But FindChildByXPath behaves like this:

    -- If the search fails then null is returned. Note, null, but not a stub object. Thus you must check for null, but not for .Exists;

    - If the search succeeds, then TestComplete tries to match found web element to the object in its Objects Tree.

      -- If the match succeeds, then TestComplete returns its object that is a wrapper over the native web element and contains all additional methods and properties provided by TestComplete. .Exist is one of such properties so it is correct to use it in test code.

      -- If TestComplete fails to match the found web element to any object in its Objects Tree, then the found native DOM object is returned. This object does not contain any method and property provided by TestComplete and test code can refer only to the native methods and properties of the given DOM object provided by the given browser. (Note that functionally equivalent methods/properties can be named differently in different browsers. .contentText is an example of such a property named differently in different browsers. Another example: val.Click() will work only for the wrapping object provided by TestComplete and will fail for the native DOM object. For the native DOM object val.click() (lower-case 'c') must be used instead.)

     

    This complexity is one of the reasons why search by XPath is not a recommended technique in TestComplete's world and is worth to be used if one needs to search for the object that is absent in regular Objects Tree provided by the Object Browser.

     

    I think that this is the reason of the problem/inconsistency that you are observing.