Forum Discussion

fmorel-isnard's avatar
fmorel-isnard
Occasional Contributor
11 years ago

Find web objects with attributes data-*

Hi everyone, 


to find web objects in our application, we use attributes data-*. 


I use something like this :


 


PropNames = Array("ObjectType","data-varname")


PropValues = Array("TextBox","ORDERMIN")


Set Object = Page.FindChild(PropNames, PropValues, 30, True)


 


Here is an example of how an element looks when using F12 in IE or FF:


 


<input class="float" type="text" size="16" data-varname="ORDERMIN"/>


 


This method works with FireFox ,Chrome and IE8. But with IE9 and later doesn't work.

If you can help me,  i would like to know why with IE9 and later this method doesn't work.



I use TC 10.30



Thank.

7 Replies

  • Hi Florent,

     


    data-varname is the HTML attribute. The FindChild method may not work with it. Can you see this property in TestComplete's Object Browser?


     


    I would suggest that you use the EvaluateXPath or FindChildByXPath method - they search for an object based on its HTML attributes. Please read the "Finding Web Objects Using XPath Expressions" article for details.


     

  • Hi Florent,

     


    The FindChild method searches for an object by its properties (listed in the Object Browser) - it doesn't search through HTML elements on the page. TestComplete gets the list of properties from a browser. This can be the reason why the code works in FF and IE 8.


     


    However, it's more accurate to use FindChildByXpath to find an object by its HTML attributes, and FindChild to find an object by its properties.


    It's expected that data-varname is specified in the outerHTML property as it contains the source code of the page. In this case, it's more correct to use outerHTML in FindChild.


     

  • Goobledy's avatar
    Goobledy
    Occasional Contributor
    Hi Florent,



    It could be because of self closing input html tag. Can you try with this one.






    <input class="float" type="text" size="16" data-varname="ORDERMIN"></input>

  • fmorel-isnard's avatar
    fmorel-isnard
    Occasional Contributor
    Hi Goobledy, Hi Tanya,



    Thanks for your help. 



    Googleby, with your suggestion, i have the same problem on IE9 and later. Thanks anyway.



    Tanya, the data-varname appears in the property outerHTML in TestComplete's Object Browser.

    My method works with FF and IE8, but with IE9 and later doesn't work. If you can explain me why...

    I have already try the 
    FindChildByXPath method and it works with IE9 and later.



    To harmonize my test between different browsers, i would like to know why the FindChild method doesn't work with IE9 and later.



    Have you others ideas about this?



    Thank you for providing the requested question.
  • fmorel-isnard's avatar
    fmorel-isnard
    Occasional Contributor
    Hi Tanya,



    Thanks again for your reply.



     The FindChild method searches for an object by its properties (listed in the Object Browser) - it doesn't search through HTML elements on the page. TestComplete gets the list of properties from a browser. This can be the reason why the code works in FF and IE 8.




    However, it's more accurate to use FindChildByXpath to find an object by its HTML attributes, and FindChild to find an object by its properties.

    It's expected that data-varname is specified in the outerHTML property as it contains the source code of the page. In this case, it's more correct to use outerHTML in FindChild. 






    Despite your explanation , I don't understand why the FindChild method works in FF and IE8. In my code "data-varname"  is not a property listed in the Object Browser, however I can find my object. How is this possible?



    Thanks.









  • Hi Florent,

     


    I cannot say why this used to work even if there are no such properties in TestComplete's Object Browser. Perhaps, there is an issue which allows doing this.


    As an alternative to FindChildByXpath, you can also use the NativeWebObject.Find method.