iterating through a RadListBox

32 posts, 0 answers
  1. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 20 Jul 2012 Link to this post

    I've got a list of entries in a page that I would like to iterate through. I was hoping to do this, without having to record each and every entry, using a count of the items and an iterator.

    I modified my code to include a reference to the item in the pages.g.cs file (by inspecting the DOM for the page). Do I need to create an entry under the tstest file?

    <d2p1:AutomationStep i:type="d2p1:AutomationStep">
          <d2p1:ContinueOnFailure>false</d2p1:ContinueOnFailure>
          <d2p1:CustomDescription i:nil="true" />
          <d2p1:Description>RadListBoxItem
    etc...

  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 25 Jul 2012 Link to this post

    Hi Max,

    The easiest way to iterate through the items in the RadListBox, is to use the 'RadListBox.Items' collection. For example, the following code will iterate through all items, scrolling and clicking on every single one.
     
    RadListBox listBox = ActiveBrowser.Find.ById<RadListBox>("RadListBoxSource");
     
    foreach (RadListBoxItem lbItem in listBox.Items)
    {
        lbItem.ScrollToVisible();
        lbItem.Click();
    }

    Here's a video demonstrating the execution.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 25 Jul 2012 Link to this post

    That still results in an error that there isn't a definition for the listbox control, warning that it could be a missing using directive or assembly reference.

  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 25 Jul 2012 Link to this post

    Hello Max,

    You need to add a using statement and reference to Telerik.WebAii.Controls.Html.dll. Please see this video on how to overcome this problem.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 26 Jul 2012 Link to this post

    The test was recorded using Test Studio. The HTML using directive was already present:

    using Telerik.WebAii.Controls.Html;

    I've checked in both Test Studio and Visual Studio and the using directive isn't underlined in red, so I don't think it is the reference that is missing.

    Edit - double checked this:

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    A reference to 'C:\Program Files\Telerik\Test Studio 2011.2\Bin\Translators\Telerik.WebAii.Controls.Html.dll' could not be added. A reference to the component 'Telerik.WebAii.Controls.Html' already exists in the project.
    ---------------------------
    OK
    ---------------------------

  6. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 26 Jul 2012 Link to this post

    Hello Max,

    Can you please send me a sample project where you are experiencing this problem? Just place it into a .zip file and attach it to this ticket. I'll try to fix it and send it back to you. 

    Kind regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 26 Jul 2012 Link to this post

    See attached. Please delete from thread once received.
  8. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 26 Jul 2012 Link to this post

    Hello Max,

    Thank you for providing the project.

    The problem is that there is conflict between the Telerik.WebAii.Controls.Html and Telerik.WebAii.Controls.Xaml namespaces. To overcome this, you need to remove or comment the using directive for the Xaml namespace("using Telerik.WebAii.Controls.Xaml"). See this short video.

    Another option is to keep both of them and use the full path to the RadListBox class in your code. Here's an example:
     
    Telerik.WebAii.Controls.Html.RadListBox listBox = ActiveBrowser.Find.ById<Telerik.WebAii.Controls.Html.RadListBox>("RadListBoxSource");
     
    foreach (Telerik.WebAii.Controls.Html.RadListBoxItem lbItem in listBox.Items)
    {
         lbItem.ScrollToVisible();
         lbItem.Click();
    }


    I also noticed that you are referencing a missing page element in a coded step in the GetAllExportsWithData test and that is why you are getting the following exception:
    c:\Users\peykov\Desktop\GetAllExports_20072012\GetAllExportsWithData.tstest.cs: Line 82: (CS1061) 'GetAllExports_20072012.Pages.GoCompletionsPage' does not contain a definition for 'ctl00_ContentPlaceHolder1_ImportsListBox' and no extension method 'ctl00_ContentPlaceHolder1_ImportsListBox' accepting a first argument of type 'GetAllExports_20072012.Pages.GoCompletionsPage' could be found (are you missing a using directive or an assembly reference?)

    Please see this article on how to resolve this.

    If you need further assistance, please let me know.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  9. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 26 Jul 2012 Link to this post

    that is quite interesting as the html and xaml assembly references are placed in the code, by default, by test studio!
  10. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 30 Jul 2012 Link to this post

    Hi,

    I agree we don't have the best solution regarding using the RadListBox in code. I've filed a bug on this behavior here. Fortunately the fix is pretty easy.

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  11. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2012 Link to this post

    Thanks. Although the points above still don't allow me to access the items one by one in that fashion. Mostly, I believe because of the control being situated within a DIV and not being built into the codebehind when recording.
  12. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 31 Jul 2012 Link to this post

    Hello,

    ...the points above still don't allow me to access the items one by one in that fashion....

    Could you elaborate on what symptom / problem you are running into? The sample code Plamen sent to you does iterate the list one by one no problem. Can you explain in what way it's not working for you?

    I believe because of the control being situated within a DIV...

    Our sample page puts the RadListBox into a DIV as you can see below. This makes me believe that's not the cause of any problem.

    <div id="RadAjaxPanel1">
        <div id="RadListBoxSource" class="RadListBox RadListBox_Office2010Silver RadListBoxButtonAreaRight RadListBoxScrollable" style="height: 200px; width: 200px;">
            <table cellpadding="0" cellspacing="0" class="rlbButtonAreaRight" style="width: 30px;">
                <tr>
                    <td>
                    <a class="rlbButton rlbTransferFromDisabled rlbDisabled rlbNoButtonText" title="To Right">
                    <span class="rlbButtonBL"><span class="rlbButtonBR">
                    <span class="rlbButtonTR"><span class="rlbButtonTL">
                    <span class="rlbButtonText"> </span></span></span></span></span></a><a class="rlbButton rlbTransferToDisabled rlbDisabled rlbNoButtonText" title="To Left"><span class="rlbButtonBL"><span class="rlbButtonBR"><span class="rlbButtonTR"><span class="rlbButtonTL"><span class="rlbButtonText"> </span></span></span></span></span></a><a class="rlbButton rlbTransferAllFrom rlbNoButtonText" href="#" title="All to Right"><span class="rlbButtonBL"><span class="rlbButtonBR"><span class="rlbButtonTR"><span class="rlbButtonTL"><span class="rlbButtonText"> </span></span></span></span></span></a><a class="rlbButton rlbTransferAllToDisabled rlbDisabled rlbNoButtonText" title="All to Left"><span class="rlbButtonBL"><span class="rlbButtonBR"><span class="rlbButtonTR"><span class="rlbButtonTL"><span class="rlbButtonText"> </span></span></span></span></span></a></td>
                </tr>
            </table>
            <div class="rlbGroup rlbGroupRight" style="margin-right: 30px;">
                <ul class="rlbList">
                    <li id="RadListBoxSource_i0" class="rlbItem">
                    <span class="rlbText">Argentina</span></li>
                    <li id="RadListBoxSource_i1" class="rlbItem">
                    <span class="rlbText">Australia</span></li>
                    <li id="RadListBoxSource_i2" class="rlbItem">
                    <span class="rlbText">Brazil</span></li>
                    <li id="RadListBoxSource_i3" class="rlbItem">
                    <span class="rlbText">Canada</span></li>
                    <li id="RadListBoxSource_i4" class="rlbItem">
                    <span class="rlbText">Chile</span></li>
                    <li id="RadListBoxSource_i5" class="rlbItem">
                    <span class="rlbText">China</span></li>
                    <li id="RadListBoxSource_i6" class="rlbItem">
                    <span class="rlbText">Egypt</span></li>
                    <li id="RadListBoxSource_i7" class="rlbItem">
                    <span class="rlbText">England</span></li>
                    <li id="RadListBoxSource_i8" class="rlbItem">
                    <span class="rlbText">France</span></li>
                    <li id="RadListBoxSource_i9" class="rlbItem">
                    <span class="rlbText">Germany</span></li>
                    <li id="RadListBoxSource_i10" class="rlbItem">
                    <span class="rlbText">India</span></li>
                    <li id="RadListBoxSource_i11" class="rlbItem">
                    <span class="rlbText">Indonesia</span></li>
                    <li id="RadListBoxSource_i12" class="rlbItem">
                    <span class="rlbText">Kenya</span></li>
                    <li id="RadListBoxSource_i13" class="rlbItem">
                    <span class="rlbText">Mexico</span></li>
                    <li id="RadListBoxSource_i14" class="rlbItem">
                    <span class="rlbText">New Zealand</span></li>
                    <li id="RadListBoxSource_i15" class="rlbItem">
                    <span class="rlbText">South Africa</span></li>
                    <li id="RadListBoxSource_i16" class="rlbItem">
                    <span class="rlbText">USA</span></li>
                </ul>
            </div>
            <input id="RadListBoxSource_ClientState" autocomplete="off" name="RadListBoxSource_ClientState" type="hidden" value="{"isEnabled":true,"logEntries":[],"selectedIndices":[],"checkedIndices":[],"scrollPosition":0}">
        </div>
    </div>

    If you can explain the symptom you are running into I'll be glad to assist overcoming whatever the hurdle is you are running into.

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  13. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 01 Aug 2012 Link to this post

    In short, the iterator doesn't work through the items in the RadListBox element.

    Please could you demonstrate code which iterates through the control on your sample page?

    I have tried adding the RadListBox element to the test elements using the DOM explorer. I have tried accessing this ByID, ByName and ByExpression. None of which I've managed to get working.

    My original question really was about adding the element to the script, if it isn't automatically recorded. This still seems to be the issue.

  14. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 01 Aug 2012 Link to this post

    Hello Max,

    Plamen already did that in his response dated July 25. He included the code and a video demonstrating how the code runs. If this approach is not working on your web application, we need to have a look and figure out what is causing the difference in behavior.

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  15. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 02 Aug 2012 Link to this post

    Hi,

    I previously submitted the code I'm working on, to demonstrate. I followed the advice and commented out the XAML using directive.

    However, I don't think the actual listbox is being added to the test resources in the actual test - this has been what I've been trying to explain:

    Element was found by backup search only! We recommend editing the element to correct the primary find expression.
    Primary Find Expression: href=/GoCompletions/Application/ImportExport/Imports.aspx?mode=GoCompletions,tagname=a
    Element was found by backup search: xpath=/html[1]/body[1]/form[1]/div[4]/div[2]/div[1]/ul[1]/li[1]/ul[1]/li[9]/a[1]
    '02/08/2012 08:58:17' - 'NotRun' : 14. RadListBoxItem('ctl00_ContentPlaceHolder1_ImportsListBox_i0'): 'Activities' action -> 'Select'
    '02/08/2012 08:58:18' - 'Fail' : 15. [SelectRadListBox_CodedStep] : New Coded Step
    ------------------------------------------------------------
    Failure Information: 
    ~~~~~~~~~~~~~~~
    Exception thrown executing coded step: '[SelectRadListBox_CodedStep] : New Coded Step'.
    InnerException:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at GetAllExports_20072012.SelectRadListBox.SelectRadListBox_CodedStep() in c:\Users\maxrussell\Documents\Test Studio Projects\GetAllExports_20072012\SelectRadListBox.tstest.cs:line 83

  16. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 02 Aug 2012 Link to this post

    in your example:

    <div id="RadAjaxPanel1">
        <div id="RadListBoxSource" class="RadListBox RadListBox_Office2010Silver RadListBoxButtonAreaRight RadListBoxScrollable" style="height: 200px; width: 200px;">
    and this can be reached using:

    RadListBox listBox = ActiveBrowser.Find.ById<RadListBox>("RadListBoxSource");
    whereas I've got:

    <div class="Column35pct">
    <div id="ctl00_ContentPlaceHolder1_ImportsListBox" class="RadListBox RadListBox_WebBlue RadListBoxScrollable" style="height:420px;width:90%;">
    but this line doesn't find the item:

    RadListBox listBox = ActiveBrowser.Find.ById<RadListBox>("ct100_ContentPlaceHolder1_ImportsListBox");

  17. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 02 Aug 2012 Link to this post

    Hello Max,

    ...but this line doesn't find the item...

    Interesting. I cannot think of any reason why that wouldn't work. I'd like to look at this problem on your computer via GoToMeeting. Let me know what time zone you are in and your availability and I'll setup the meeting. I'm in Austin, TX which is Central Time (GMT -6).

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  18. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 03 Aug 2012 Link to this post

    My availability isn't good until Tuesday of next week. GMT.
  19. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 03 Aug 2012 Link to this post

    Hi,

    No problem for me. Just let me know when you're available. Also, if it would help overcome the timezone difference, I can ask one of my other team members located in Sofia, Bulgaria to meet with you. I think they are much closer to your timezone and could meet during your regular business hours.

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  20. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 07 Aug 2012 Link to this post

    This might be best tomorrow. Via Sofia.
  21. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 07 Aug 2012 Link to this post

    Hello Max,
    I've went ahead and sent you a meeting request for tomorrow. Go ahead and update the time if it doesn't work for you.

    All the best,
    Stoich
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  22. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 10 Aug 2012 Link to this post

    Hi Max,
    I'm glad we were able to workout the issue. To sum it up the problem was as follows:
    You were looking for the RadListBox element in code by its ID:
    RadListBox rlb = ActiveBrowser.Find.ById<RadListBox>("RadListBoxId");
    we managed to determine that Test Studio cannot identify the element as a RadListBox for whatever reason. So we reworked the code like this:
    Element e = ActiveBrowser.Find.ById("RadListBoxId");
    RadListBox rlb = e.As<RadListBox>();
    and this worked.

    I spent some time researching this. I did not experience the same problem in my environment.
    Try out the following code on your end:
     
    RadListBox rlb = ActiveBrowser.Find.ById<RadListBox>("RadListBoxSource");
    Log.WriteLine("Found this:"+rlb.ToString());
     
    foreach (RadListBoxItem rli in rlb.Items) {
     rli.MouseClick();  
    }

    This worked fine on my end. Interestingly at first this wouldn't compile because RadListBox is an ambiguous reference between Telerik.WebAii.Controls.Html.RadListBox and Telerik.WebAii.Controls.Html.RadListBox.Xaml.

    I had to add the following lines of code to make it work:
    using RadListBox = Telerik.WebAii.Controls..Html.RadListBox;
    using RadListBoxItem = Telerik.WebAii.Controls.Html.RadListBoxItem;

    Did you use the same lines as well? Making a reference to the wrong element (the XAML Listbox instead of the HTML) might cause problematic behavior.

    Greetings,
    Stoich
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  23. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 10 Aug 2012 Link to this post

    Yes - that works for me, however I was previously told to comment out the XAML using directive, which also works (there is a ticket raised to address the namespace confusion I think):

    using Telerik.WebAii.Controls.Html;
    //using Telerik.WebAii.Controls.Xaml;
  24. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 13 Aug 2012 Link to this post

    Hi Max,
    I was not aware. Commenting out using Telerik.WebAii.Controls.Html; is a different way of achieving the same effect: getting rid of the ambiguous reference.

    All the best,
    Stoich
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  25. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 04 Oct 2012 Link to this post

    Cody raised an issue for this:
    http://www.telerik.com/support/pits.aspx#/public/test-studio/12090

    No fix has been scheduled, is one going to be scheduled?

    thanks
  26. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 04 Oct 2012 Link to this post

    Hi Max,

    No there is not going to be a code change about this. We have concluded that this behavior is by design. Because there is a RadListBox control in both HTML and Silverlight, you must be intelligent enough when dealing in code to handle this issue, either by commenting out the "using xxxx" statement that you don't need or by using the correct explicit name space qualifier "Telerik.WebAii.Controls..Html.RadListBox" as Stoich proposed. Either approach will overcome the compile error you can get.

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  27. Max
    Max avatar
    18 posts
    Member since:
    Jul 2012

    Posted 05 Oct 2012 Link to this post

    Okay thanks - kind of goes against what was said earlier in this thread, as it does seem strange to default to having both, if there is a clash in the namespace from a default recording, perhaps that should be documented?
  28. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 05 Oct 2012 Link to this post

    Hello Max,

    "...kind of goes against what was said earlier in this thread..."

    I understand the sentiment and yes I admit it is a change in direction from me. After we talked about it more with our software developers we all came to the same decision that the approach we're currently taking is the best approach for these reasons:
    • When you start writing code we, Telerik, have no idea if you will be writing code for a Silverlight application or a HTML application.
    • Since we cannot automatically detect this, we have to either include both "using xxxx" statements or neither. We concluded it would be better to include both.
    • When you "customize step in code" our code generation will generate code that uses the fully qualified namespace which is compatible with having both "using xxxx" statements. We're expecting customers to follow after this pattern.

    The reason you're running into trouble is that you're trying to use the shorthand method of not specifying the fully qualified namespace. We consider this an advanced programmer technique and expect such people to be intelligent enough to be able to handle it, and I know you are an intelligent person.

     Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  29. Humberto
    Humberto avatar
    8 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2013 Link to this post

    Hello,

    Sorry to hijack this post but it does seem similar to something I am trying to do.  However I am interested to know if it's possible to do this in the Pages.g.cs file, within the Pages class?

    Declaractively detect/find a List or a Collection of Menu items?

    Something along the lines of:

     public List<ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor> MenuItems
    {
    get { return Get<List<ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor>>("tagname=a"); }
    }

    These are children of a Menu UI element:
     public HtmlControl Menu
    {
    get { return Get<HtmlDiv>("id=ctl00_RadMenu1"); }
    }

    So basically I am trying to find the menu sub items and iterate over them clicking on each one.


    I realize that the "user actions" I would not do in the Pages class...but what about the declaration?
  30. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 26 Mar 2013 Link to this post

    Hello Humberto,

    There are a couple of problems with what you describe you want to try to do:
    1) The Pages.g.cs file is very frequently regenerated by Test Studio (nearly constantly)
    - Everytime you open your test project
    - Anytime you add/delete an element including adding/deleting test steps
    - Anytime you run a test
    - If using our VS plug-in, anytime you build the project in VS

    Any changes you try to make to this file will be overwritten/discarded.

    2) The get<> function is restricted to returning a single element that is either a HtmlControl object or derives from the HtmlControl class. It cannot be used to return anything else, including a List.

    If you implement it in your own code (instead of trying to place it in Pages.g.cs) you could do the equivalent like this:

    public System.Collections.ObjectModel.ReadOnlyCollection<ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor> MenuItems
    {
        get
        {
            return Find.AllByExpression<HtmlAnchor>("id=ctl00_RadMenu1","|","tagname=a");
        }
    }

    The above find expression says find the element having the ID ctl00_RadMenu1 and then find and return a list of all the anchors underneath/attached to that element.

    Regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top