Forum Discussion

tamaradepaus's avatar
tamaradepaus
New Contributor
12 years ago

Selecting invisible item in drop down list (jscript)

Hi,



I'm currently testing a webapplication which has a dropdownlist which shows at selection about 6 items. The amount of items and the location of the items is variable.



I would like to create a script in Jscript which selects the correct item from the box, whether it's already visible or not.



At the moment I've got this script, but it only works if the item is in the top 6 list.




function SelectMerchant(){


    var page = Sys.Browser(BrowserType).Page(BaseURL).NativeWebObject;


    var account = page.Find("innerText", "Select an Account");


    


    account.Click();


    


    var merchant = page.Find("innerText", "Sound of Data");


    


    merchant.Click();


}



Can anybody help me out with this? Thanks in advance.

4 Replies

  • Hi Tamara,



    As I see, this combobox doesn't seem like a 'standard' combobox, so you will have to develop a custom script to change that combobox value.



    If I understood correctly your code, you can try this code:





    function selectTheItem()

    {

        Browsers.Item(btChrome).Navigate("http://my.tst.soundofdata.com/");

    var panel = Sys.Browser().Page("http://my.tst.soundofdata.com/").Header(0).Aside(1).Panel(0).Panel("account_selector_chzn");

    panel.Link(0).TextNode(0).Click(135, 10);  // This deploys the combobox?



    var panel2 = panel.Panel(0);

    var theItem = panel2.Find("innerText", "Sound of Data");

    theItem.Click()

    }





    I'm not sure if this is going to work, but I hope it helps. Good luck!
  • Hello Tamara,



    When I face a problem that I don't really understand what happens in my code, I first try to record the script first. I encourage you to try it!



    There is an approach to fix the script






    function SelectMerchant(){


        var page = Sys.Browser(BrowserType).Page(BaseURL).NativeWebObject;


        var account = page.Find("innerText", "Select an Account");


        


        account.Click();


        


        var merchant = account.Find("innerText", "Sound of Data");


        


        merchant.Click();


    }

    [/cоde]



    This will search "Sound of Data" inside the account object, so it will be faster and it will make sure that no other object with the same innerText is found.



    If this doesn't solve the problem, you can try:






    function SelectMerchant(){


        var page = Sys.Browser(BrowserType).Page(BaseURL).NativeWebObject;


        var account = page.Find("innerText", "Select an Account");


        


        account.ClickItem("Sound of Data);


    }

    [/cоde]




    If neither of them work, try to record the script.



    Hope it helped!
  • Hi Javier,



    Thank you for your answer. I tried both code solutions, but unfortunately both solutions don't work out for me.



    When recording,  it get below text, but in there everything is fixed. When I add a new account, the code doesn't work anymore.




    function Test1()


    {


      var panel;


      var panel2;


      Browsers.Item(btChrome).Navigate("http://my.tst.soundofdata.com/");



      panel.Link(0).TextNode(0).Click(135, 10);


      panel2 = panel.Panel(0);


      panel2.Drag(405, 39, -5, 86);


      panel2.TextNode("account_selector_chzn_o_12").Click(133, 21);


    }



    I'll work for now with above code and when I find a more flexible solution I'll post it here.

  • josette_merhy12's avatar
    josette_merhy12
    Occasional Contributor
    if you try to open the popup of the dropdown while finding the arrow of it and pressing keys of the elemant name on the arrow, the element will b selected.






    function SelectMerchant(){


        var page = Sys.Browser(BrowserType).Page(BaseURL).NativeWebObject;


        var account = page.Find("innerText", "Select an Account");

     


        var arrow = account.Find("name","arrow",4);



       arrow.Click(1,1);



      arrow.keys("Sound Of Data");


    }

    [/cоde]