Forum Discussion

VVinay's avatar
VVinay
New Contributor
13 years ago

Object Identification only through Property-Value pair?

Hello,



(Ours' is a web based application. We are only using script based testing, writtien in C# script language.)

I am aware of how we use name mapping for identifying the objects and perform action on it. But I am yet to discover a way in which any control can be identified by only its property-value pair. We are on the verge of writing a frame work, if this concept is addressed we would be grateful.



example: for google application, consider performing an operation on the search "text box". If we want a unique property for this object, it is Property: idStr, and Value: gbqfq.



Traditionally it is done something like this:  


fieldset = iexplore["pageGoogle"]["panelMngb"]["panelGb"]["panelGbw"]["panelGbq"]["panelGbq2"]["panelGbqfw"]["formGbqf"]["fieldsetGbqff"];


textbox = fieldset["panelGbqfqw"]["panelGbqfqwb"]["tableLstT"]["cell"]["table"]["cellGsibA"]["panel"]["textboxGbqfq"];


textbox["SetText"]("testcomplete");



What we are looking forward is something like this:



var editBoxGoogleSearch = page["FindObject"](idStr, gbqfq);

editBoxGoogleSearch["SetText"]("testcomplete");



where, "FindObject" is a function which will search for object with property: idStr, and value: gbqfq.

For this type of function to work, first I assume, we have to assign the entire webpage as a container, with in which all searches will happen.



Thanks in advance. Anticipating for a response.








5 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Vinay,



    TestComplete provides various search functions exactly for this purpose:

    * Page.FindChild - searches for a web page element by one or more property-value pairs;

    * Page.NativeWebObject.Find - searches for a web page element by its tag name and a single property-value pair;

    * Page.EvaluateXPath - locates a web page element by XPath.



    So, you can use any of the following - whatever you like most:

    ' Searching by one property-value pair

    var editBoxGoogleSearch = page["FindChild"]("idStr", "gbqfq", 15 /* search depth */);



    ' Searching by multiple property-value pairs

    var editBoxGoogleSearch = page["FindChild"](

        ["TAGNAME", "idStr"], // property names

        ["INPUT", "gbqfq"], // property values

        15 /* search depth */);



    ' Searching by the tag name and one property-value pair

    var editBoxGoogleSearch = page["NativeWebObject"]["Find"]("idStr", "gbqfq", "input");



    ' Searching by XPath

    var res = page["EvaluateXPath"]("//INPUT[@id='gbqfq']");

    var editBoxGoogleSearch = (new VBArray(res)).toArray()[0];
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    If I may add, NameMapping does work on the concept of property/value pair.  That's how name-mapping identifies objects.  In fact, you can (and probably should) map most objects with a combination of 2 or more properties and their corresponding values, especially in cases where objects may be similar enough as to be easily confused.
  • VVinay's avatar
    VVinay
    New Contributor
    Thanks for your reply, Helen,



    We are now using NativeWebObject function for identifying the controls. Although I have a minor doubt on the 1st and 2nd way you have suggested here. Even though the "search depth" is an optional attribute, how can we determine in what search depth the object is supposed to be present?
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Vinay,



    Even though the "search depth" is an optional attribute, how can we determine in what search depth the object is supposed to be present?
    The search depth for FindChild equals the number of hierarchy levels (intermediate objects) between the object on which you call FindChild and the sought-for object. You'll need to examine your application in the Object Browser to determine that.



    For example, let's suppose that we have a SubmitButton object with the following FullName value in the Object Spy:

    Sys.Process("IEXPLORE").Page("http://example.com").Form("aspnetForm").Panel(0).SubmitButton("Login")
    and we want to use the Page.FindChild method to find this SubmitButton.



    There're two objects in the hierarchy between Page and SubmitButton - Form("aspnetForm") and Panel(0).

    So, we need to use the search depth = 2.



    It's a basic example, but if your object hierarchy is dynamic, you'll probably need some trial and error to determine the search depth that will work for all cases.
  • VVinay's avatar
    VVinay
    New Contributor
    Hello Helen,



    Indeed you are right. I think we'll be using all the 4 functions, which ever fits the context.



    Thank you