Forum Discussion

arphaxad78's avatar
arphaxad78
New Contributor
14 years ago

Map a New Object Using ID

I'm new to TestComplete and am running into some trouble with creating test cases.  I've walked through most of the video tutorials but still haven't been able to find an answer to this question:



I need to write a test case script that's more advanced than just grabbing an object based off of its position or class...I need to grab a button (a div) off of its ID on the page.  How do I do this?



Secondly after answering this, where should I have read/seen this in the help?  I hate asking a question that's obvious so I'd like to know where to look next time when I run into something like this.



Thanks!
  • arphaxad78's avatar
    arphaxad78
    New Contributor
    I'll add a little more to this question to make it clearer.  I currently have a button that I want to click using Chrome.  When I use the "Map New Object" option on this button I get:

    Aliases.chrome.pageBlahBlahCo.panelPopupaui330311554.panelAui330311563.panel.panelAui330311553.buttonAui330316187


    We are using YUI for these pages so many of the elements have IDs that change.  I don't want to have to set IDs for each of the panels above.  If I add an ID to just the button itself, how can I just map to the ID and not have the path to the other panels?  Do I have to set hard-coded IDs to each of the parent panels for this to work?



    How can I call an object on the page by just using its ID?



    Is there any way to grab objects by using a CSS Selector?
  • Hi Michael,


    When you map an object, TestComplete maps all its parent objects. This is needed to make the search faster.


    You said that ids of your page's elements change. I'm not a YUI guru, but maybe you can use wildcards (* and ?) in mapping settings to mask the parts that change?


    Another possible solution is to assign a persistent id to the needed button and then obtain this button in your tests by using the Page.NativeWebObject.Find method: Page.NativeWebObject.Find("id", "ID_of_your_button", "INPUT").


    For information on searching for web page elements, see Finding Objects on Web Pages.


    Also, the following section provides information on some specific mapping approaches. Maybe, it will help: http://smartbear.com/support/viewarticle/12451/.