Forum Discussion

nedbacan's avatar
nedbacan
Frequent Contributor
2 years ago
Solved

Selecting an item from List box based on the name using

Hello, I am fairly new to Test Complete and just learning, can someone show me using my example I provided here on selecting the specific item (see screenshot) from the web List box that I show highlighted in the Element screen ? 

 

What is the best method to use to search and select (click) the item as the current item in the menu?  I would also like once I get the basic to search the item in the list box that I have stored in the patient variable where I would get from another screen (another script test/keyword test) so I can look for it. 

 

Here are two methods I found; page.NativeWebObject.Find and aqObject.CheckProperty but not sure which is best to use in this case. If you know something better and please if you can provide it with this example.

 

I would also like once I get the basic to search the item in the list box, I would like to reuse the patient variable where I would get from another screen (another script test/keyword test) and apply it to the search item on the list. 

 

Can someone show me how to apply it in JavaScript using the sample I provided? 

 ELEMENT SCREEN:

 

 

SPY TOOL:

 

 

  • In basic scripting, without a dynamic variable, finding and clicking the object is just:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='Refracnadim1 1_Refractionist']").Click();

     

     And if you're using a Project.Variable, it would be something like:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='" + Project.Variable.ListItemX + "']").Click();

     

     

    That being said, it looks like you are using NameMapping within TestComplete, so if it is indeed a mapped object, to click it you would just use:

     

     

    Aliases.browser.pageWHATEVER.label.panelRefracnadim11Refractionist.Click();

     

     

    If this object's xpath has a dynamic property variable that you pass in from another test, you'll need to insure:

    1. You are using Project.Variable and not a ProjectSuite.Variable.
    2. You'll want to update the object in NameMapping to use the Project.Variable in the property criteria (see how here). EX: if your variable name was ListItemX for example, the xpath in the NameMapping would be //div[., '%ListItemX%'].
    3. (Optional) Change the object Name and Alias from panelRefracnadim11Refractionist to panelRefracnadimRefractionist (or similar) for ambiguity and assuming the number changes. This allows you to only need 1 mapped object for every item in the list - assuming you are using the variable approach to pass in the dynamic part of the xpath, and assuming the parent object is mapped appropriately (IE: mapping the container box the list items are in //div[contains(@class, 'practitioner-container')]).

     

2 Replies

  • Kitt's avatar
    Kitt
    Regular Contributor

    In basic scripting, without a dynamic variable, finding and clicking the object is just:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='Refracnadim1 1_Refractionist']").Click();

     

     And if you're using a Project.Variable, it would be something like:

     

    Sys.Browser("*").Page("*").FindElement("//div[.='" + Project.Variable.ListItemX + "']").Click();

     

     

    That being said, it looks like you are using NameMapping within TestComplete, so if it is indeed a mapped object, to click it you would just use:

     

     

    Aliases.browser.pageWHATEVER.label.panelRefracnadim11Refractionist.Click();

     

     

    If this object's xpath has a dynamic property variable that you pass in from another test, you'll need to insure:

    1. You are using Project.Variable and not a ProjectSuite.Variable.
    2. You'll want to update the object in NameMapping to use the Project.Variable in the property criteria (see how here). EX: if your variable name was ListItemX for example, the xpath in the NameMapping would be //div[., '%ListItemX%'].
    3. (Optional) Change the object Name and Alias from panelRefracnadim11Refractionist to panelRefracnadimRefractionist (or similar) for ambiguity and assuming the number changes. This allows you to only need 1 mapped object for every item in the list - assuming you are using the variable approach to pass in the dynamic part of the xpath, and assuming the parent object is mapped appropriately (IE: mapping the container box the list items are in //div[contains(@class, 'practitioner-container')]).

     

  • nedbacan's avatar
    nedbacan
    Frequent Contributor

    Kitt  I appreciate your help.  I was able to perform the first part of my question using the Aliases Browser and FindElement. as you described in the following. Very simple, now I will work on the second part and let you know how I did.  Thank you again 

    Aliases.browser.pageWHATEVER.label.panelRefracnadim11Refractionist.Click()