KendoMenuItem - Find expression on Kendo UI elements

4 posts, 0 answers
  1. SHK
    SHK avatar
    11 posts
    Member since:
    Jul 2015

    Posted 04 Nov 2015 Link to this post

    Hi ,

    How do we use 'find by expression' code on Kendo UI elements in test studio.

    Example: I have 'KendoMenuItem'  which I want to click by using the code .

    I want to later turn it into a reusable ​test and be able to click different menu items each time by passing the 'innertext' as variable/parameter.

    On recording the properties of one such element look like this -

    ControlType: Telerik.TestingFramework.Controls.KendoUI.KendoMenuItem

    Expression: data-role=menu,role=menubar,|,TagName=li,InnerText=^Sales

    cam you please help me write a code to get this element clicked.

     Best Regards,

    Sprithi  HK

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 06 Nov 2015 Link to this post

    Hello Sprithi,

    Please find the bellow code which finds all menu items in the page and click on the one that contains a specific text:

    IList<KendoMenuItem> itemList = ActiveBrowser.Find.AllByAttributes<KendoMenuItem>("role=menuitem");

    Log.WriteLine(itemList.Count.ToString());

    KendoMenuItem item = itemList.Where<KendoMenuItem>(_a => _a.InnerText.Contains("First Item")).FirstOrDefault();

    item.Select();

    System.Threading.Thread.Sleep(3000);

    Hope this helps.

    Regards,
    Boyan Boev
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. SHK
    SHK avatar
    11 posts
    Member since:
    Jul 2015

    Posted 16 Mar in reply to Boyan Boev Link to this post

    Hi Boyan,

    Thank you for the reply. I have been looking at other things so couldn't check this sooner.

    Can you please send this code in VB. I tried to convert this to VB but it doesn't work. I must admit I am not so familiar with using the Where clause in the vb code.

    Best Regards,

    Sprithi H K

  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 21 Mar Link to this post

    Hi Sprithi,

    You can use For Each instead of Where. Here is the code in VB:

    Dim itemList As IList(Of KendoMenuItem) = ActiveBrowser.Find.AllByAttributes(Of KendoMenuItem)("role=menuitem")
     
    Log.WriteLine(itemList.Count.ToString())
     
     
    For Each item As KendoMenuItem In itemList
     
        If item.InnerText.Contains("First Item") Then
            item.Select()
        End If
    Next
     
     
    System.Threading.Thread.Sleep(3000)

    Let me know if that helps.

    Regards,
    Boyan Boev
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top