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

Error in coded step when trying to click on KendoMenuItem

1 Answer 113 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yan Jun
Top achievements
Rank 1
Iron
Veteran
Yan Jun asked on 11 Sep 2020, 03:23 AM

Hi,

I was trying to look for a Kendo Menu to click on using C# code but I keep hitting error "System.NullReferenceException: Object reference not set to an instance of an object."

The DOM where the element is located is as per the attached image.

I tried using the element reference from Element Repository to perform actions but I keep hitting error:

1.Pages.Home.Menu_Setup.MouseHover(0, 0, ArtOfTest.Common.OffsetReference.AbsoluteCenter);
2.Pages.Home.Menu_Setup_Contract.MouseHover(0, 0, ArtOfTest.Common.OffsetReference.AbsoluteCenter);
3.Pages.Home.Menu_Setup_Contract_MasterPriceList.Click(false);

 

Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[Coded_Master_Price_List_CodedStep1] : Master Price List Entry'.
InnerException:
System.ArgumentException: Invalid tag name 'span' for this control. Control was expecting 'li'

 

Then the code is amended based on the documentation here to try looking for the element's parents and perform clicking:

1.IList<KendoMenuItem> itemList = ActiveBrowser.Find.AllByAttributes<KendoMenuItem>("role=menuitem");
2.HtmlFindExpression li = new HtmlFindExpression("title=SETUP","innertext=~Setup");
3.li.AddHierarchyConstraint(new HierarchyConstraint(new HtmlFindExpression("role=menuitem"), -1));
4.KendoMenuItem menuSetup = Find.ByExpression<KendoMenuItem>(li);
5.menuSetup.Click();

 

Then the error is hit:

Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[Coded_Master_Price_List_CodedStep1] : Master Price List Entry'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.

 

Can I please ask for help on which part is wrong in this code?

Thank you.

 

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 15 Sep 2020, 09:12 AM

Hi Yan Jun,

Thank you for sharing part of you code and details about what you have already tried on your end.

I wanted to reproduce the same errors against a publicly accessible demo of Kendo UI Menu, but it worked there. I will need you help to better understand what is causing those exception that you experienced, so we can work together to automate this test scenario. Please follow up on the topics below.

  • Please find the attached sample test and explore it on your end. The demo application does not have any data to show, but the actions are all successful.
  • It seems to me that some of the elements are of a different type than the expected for this action and that is causing the issue. If you can share the .tstest and .tstest.cs files associated with your test, I can explore them further and provide more details.
  • We recommend that you use find expressions, rather than references to the Pages object. That ensures a more stable local and remote execution of your tests. I assume that you have linked to this section of the article and tested it on your end. I assume that the reason for the NullReferenceException is the fact that there are 2 <li> elements with the same attribute "role=menuitem". As a result Test Studio tries to find a child for the first <li> element in the DOM tree, but it does not exist. You can try using different find expression, like the "id" attribute for example.
  • I would be best if I can also test against your application and have a sample Test Studio project to work with. I will be able to explore this test scenario and provide better assistance.

I hope the above details will be helpful. Please do not hesitate to contact us again, if you have any follow up questions or you need further guidance.

Regards,
Plamen Mitrev
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
General Discussions
Asked by
Yan Jun
Top achievements
Rank 1
Iron
Veteran
Answers by
Plamen Mitrev
Telerik team
Share this question
or