This is a migrated thread and some comments may be shown as answers.

KendoMenuItem - Find expression on Kendo UI elements

3 Answers 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 04 Nov 2015, 09:39 AM

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

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 06 Nov 2015, 03:03 PM
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!
0
Roger
Top achievements
Rank 1
answered on 16 Mar 2016, 09:59 AM

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

0
Boyan Boev
Telerik team
answered on 21 Mar 2016, 08:38 AM
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!
Tags
General Discussions
Asked by
Roger
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Roger
Top achievements
Rank 1
Share this question
or