Forum Discussion

tandreys's avatar
tandreys
Occasional Contributor
9 years ago

TC11.20 EvaluateXPath not always returning object

Hi,

I'm having trouble with EvaluateXPath sometimes it's working, sometimes not on the same xpath.

I did had this problem on TC10.

In my case, QuerySelector is working so I was able a change my function.

 

Does anybody have seen this?

 

2 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Tandreys,

     

    Could you please share the problematic code with us?

    • rrivest's avatar
      rrivest
      Contributor

      The basic problem is the DOM Model not updating fast enough.... this often occures in IE....

       

      Instead, use a timed search for that xPath..... Here's a sample code in C# that I use as a generic function

       

      function TimedSearchXPath(msdelay,source,ElementType,StrValue) {

      var ellapse = HISUtils["StopWatch"];

      ellapse["Start"]();

      var UIObject = null;

      while ((UIObject == null) & (ellapse["Split"]() < msdelay)) {

      var UIObject = source["FindChildByXPath"]("//"+ElementType+"[contains(@data-ui-test,'"+StrValue+"')]",true);

      }

      if (UIObject == null) {

      Log["Message"]("Search delay has expired");

      return null;

      }else

      return UIObject;

      }