Forum Discussion

hoadoan's avatar
hoadoan
Contributor
14 years ago

can't select item in combo box

Hi all,



I recorded a script in which I selected a combo box and it's used by Testcomplete 6. The problem is that when the script is playback, the item isn't selected on web page

The playback work fine to second combo box.



Please help me!!!



 w2["Cell"](2, 1)["Select"]("cboMarket")["ClickItem"]("511"); //-->it's doesn't work

 w2["Cell"](3, 1)["Select"]("cboOwner")["ClickItem"]("Z Network");//-->it work fine





Thanks,

Hoa

 
  • Hi,



    If you meant clicking an item by index in the first line (the marked with "it's doesn't work"), remove quotes from ClickItem's parameter value.
  • Hi Jared,



    Thanks for your response.



    I meant clicking an item by name NOT id . This is recorded script. and I surprise that why it can't playback although it's OK to the second combo box



    Regards,

    Hoa
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I've had a similar experience in my web app I've been testing.  If the contents of the combo box are populated from an SQL database using a jquery or some such thing, there may be a delay between when the page is rendered and when the box is populated with the items.  



    Just as a test, try putting a Delay(2000) before that select and see if that alleviates it.  If so, you might want to consider putting a WaitProperty call on that ComboBox to wait for it to be populated before you attempt to click on any items.
  • Hi Robert,



    I try to apply your method. I use delay(2000) before selecting combo box but the value isn't select.

    Although the value "511" is recorded as selected value in test log but it isn't selected on webpage



    Please help me.



    Thanks,

    Hoa
  • Hi all,



    I found that there is a change in this combo box

    It has a option group named "Active" and "Inactive". The structure of combo box as following. 

    <select id="cboMarket" onchange="javascript&colon;getSubmarkets();" name="cboMarket">



    <optgroup label="Active">

    <option value=""></option>

    </optgroup>






    <option value="325">511</option>




    <option value="258">Abilene</option>

    <option value="1">Albany</option>






    <optgroup label="Inactive">





    <option value="101">!Miami - MVN</option>




    <option value="45">* Daytona Beach</option>

    </optgroup>






    This is the reason the value isn't selected correctly on webpage. And we have the wrong result as following

    w2["Cell"](2, 1)["Select"]("cboMarket")["ClickItem"]("511") //no selected value on web page

    w2["Cell"](2, 1)["Select"]("cboMarket")["ClickItem"]("Abilene") //511 is selected on web page

    w2["Cell"](2, 1)["Select"]("cboMarket")["ClickItem"]("Albany")//Abilene on web page



    Please help me how to select a correct automatically on web page
  • Hi,



    Try iterating through items of your combo box from a script by using its wItemCount and wItem properties. On each loop iteration, check whether the current item's caption is the one you need. Once you find the needed item, click it by index (the current value of the loop counter).
  • Hi Jared,



    I used your solution but I have the problem in syntax. 

    The message syntax error is always shown at tbl["cboMarket"].["ClickItem"](i);

    Please view my below script and help me correct it.



    var itemCount=tbl["cboMarket"].wItemCount;  


    for(i = 0; i < itemCount-1; i++)

        {

          if (tbl["cboMarket"].wItem(i)="511")then

          {

            tbl["cboMarket"].["ClickItem"](i);

          }        

        }


    Thanks,

    Hoa
  • Hi,



    You get syntax errors because your syntax is incorrect. The correct syntax is 'tbl["cboMarket"]["ClickItem"](i)' or 'tbl.cboMarket.ClickItem(i)', but not 'tbl["cboMarket"].["ClickItem"](i)'
  • Hi Jared,



    Thanks for correcting my syntax. But I still have the same issue. The selected value isn't shown correctly on webpage






     for(i = 0; i < itemCount-1; i++) 

      { 

        if (tbl["cboMarket"].wItem(i) =="Albany") 

        { 

          tbl["cboMarket"]["ClickItem"](i);

          break; 

        }         

      }




    The result is will be 

    if (tbl["cboMarket"].wItem(i) =="511")  //blank is selected on web

    if (tbl["cboMarket"].wItem(i) =="Abilene") //"511" will be selected on web

    if (tbl["cboMarket"].wItem(i) =="Albany") //"Abilene" will be selected on web



    Please help me
  • Hi,



    In this case, this behavior seems to occur due to the way the item index is calculated. Can we have an example of the web page containing a combo box which works in the same way?