Forum Discussion

marin's avatar
marin
Frequent Contributor
12 years ago

Problems with EvaluateXPath() and FindChild() in IE9 using TC 9.10

Hello all,

I wonder if anybody came across the following problem after updating from 9.0 to 9.10:

when searching for objects vie EvaluateXPath() or FindChild(), the searched objects will not be found in IE9, whereas in FF 15.0.1 the objects are found without issues.



Sample code:







//Prototype declaration - indexed array

Array.prototype.indexOf = function(item)

{

  for (var i = 0; i < this.length; i++)

  {

    if ((i in this) && (this == item)) return i;

  }

  return -1;

}





function NewArray()

{

  return new Array();

}





var lnk = FindChildNodeXPath(mappedPageObject, "A", "id", "myLinkId");



function FindChildNodeXPath(objTarget, strElement, strAttribute, strAttrValue)

{

  var valueArr = NewArray();

  var tmp = objTarget.EvaluateXPath("//" + strElement + "[@"+ strAttribute + " = '" + strAttrValue + "']");

 

    if (tmp != null)

    {

      var arr = (new VBArray(tmp)).toArray();

      valueArr[0] = arr[0];

    }

    else

    {

      Log.Message("Find child node via XPath: the element was not found.");

    }

    

    

  return valueArr[0];

}





The odd thing is that when debugging this method and stepping through, the searched object would be found...



What could be causing this?



Many thanks for any hints,



Marin

3 Replies

  • marin's avatar
    marin
    Frequent Contributor
    Hello all,



    in the meantime I found the real cause of the problem: it has apparently something to do with handling of arrays.

    As already pointed out in the initial mail, the difference was obvious when changing from 9.0 to 9.10 - and only IE related.



    Now I found out that it is the array instantiation that is the core of the problem:

    When adding a delay of 1000 ms after instantiation of array, the code would run correctly in IE as well.

    Same code would not run in IE without mentioned delay  (i.e. assignment of values to array would fail because the instantiated array object would not be found).



    I wonder if this is a known issue?



    Regards,



    Marin
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Marin,


     


    Do you mean adding a delay after this line:


    var arr = (new VBArray(tmp)).toArray();


    solves the issue?


     

  • marin's avatar
    marin
    Frequent Contributor
    Hello Tanya,



    I had to add the delay immediately after the array instantiation. I used the new feature to check for browser family to add the delay only if IE is used:



    var valueArr = new Array();

     

      if(Browsers.CurrentBrowser.Family == Browsers.btIExplorer)

        Delay(1000);



    In this scenario the conversion var arr = (new VBArray(tmp)).toArray(); works correctly without having to add the delay there...



    Thanks,



    Marin