Forum Discussion

Lianne's avatar
Lianne
New Contributor
3 months ago

ClickItem not selecting the proper item from a dropdown

I am working with TestComplete for the first time, evaluating it for ease of use for our organization. I'm a tester, not a developer

I tried recording a test that fills out a form including a dropdown list. The code generated by a record as JavaScript shows as

browser.pageLeaveHomePageGc.framePtifrmtgtframe.formW3lvLeaveTranG.selectGDerivedW3lvDescr500.ClickItem("Vacation");

However, when I play it back, it just clicked on the first (sometimes second) item in the dropdown list, not the item that I recorded selecting. There are a large number of items in the dropdown list (20+)

Is there a different sort of command that would select the correct item? I tried recording as script and recording as keyword, but still got the same result

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    I've seen this type of behavior before when the contents of the dropdown list are created dynamically.  In other words, the items that appear in the list aren't generated/populated until the list is displayed.  A three or four step process might do the trick for you.  

    The four step approach I would try is this:

    1. Drop down the combo list
    2. Delay 250 ms so the combo can populate
    3. Refresh TestComplete's object list so that you know it has the list items
    4. Click the item you want

    Sadly, I don't do JavaScript.  I'm a VB script only guy. In VBScript that would look something like this:

    Set TestCombo = browser.pageLeaveHomePageGc.framePtifrmtgtframe.formW3lvLeaveTranG.selectGDerivedW3lvDescr500
    TestCombo.DropDown
    Delay 250
    TestCombo.Refresh
    TestCombo.ClickItem("Vacation")

    I think you should be able to accomplish that in a Keyword test using the available functions.  I'm more than a little out of practice using keyword tests.

    Best regards,
    John

    P.S. Pro tip on name mappings.  Shorten those names up and standardize the terms when you create them.  Life will be easier in the future if you do that. The ones TestComplete creates are always too long.  It makes reading code painful. 

    I try to keep them to a max of ten to twelve characters when I can.  For "select" I'd use "sel".  For "frame" maybe "frm".  Use whatever makes sense to you and be consistent.

     

  • Lianne's avatar
    Lianne
    New Contributor

    The image shows no values for the dropdown. Is there an easy way to put the pause into the javascript line? I tried searching, but couldn't find anything.

    • Hassan_Ballan's avatar
      Hassan_Ballan
      Contributor

      Did the dropdown actually happen? 
      To simplify things for you, use KeywordTest. Any KeywordTest can be converted into script, but not the other way around. You just need to drag and drop, and configure the required operation.

       

  • The click is supposed to go on an item called "Vacation", in the "Test Log" you can view each item picture to see what was happening on the screen before and when the action took place.

    You can view your Mapped Objects browser.pageLeaveHomePageGc.framePtifrmtgtframe.formW3lvLeaveTranG.selectGDerivedW3lvDescr500 to validate and manually adjust the mapping.

    Is your 20+ list slow to load? if so you are attempting to click on a moving target and I suggest you add a short pause.