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

System.NullReferenceException when trying to locate element

7 Answers 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jared
Top achievements
Rank 1
Jared asked on 02 Sep 2015, 05:35 PM

Hi All,

 I have seen about 5 or 6 threads on this issue with no real solution or explanation given. I am in Visual Studio 2013 with Telerik Testing Framework. I am using examples provided by your support staff. I have added ArtOfTest.WebAii and Telerik.TestingFramework.Controls.KendoUI references to my solution. Then I have added the following namespaces to my test file (most of which I know are not necessary):

using ArtOfTest.WebAii;
using ArtOfTest.WebAii.Controls;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.ObjectModel;
using NUnit.Framework;
using Telerik.TestingFramework.Controls.KendoUI;

 

namespace VNextTelerik
{
    [TestFixture]
    public class Class1
    {
        public Manager myManager;
 
        [SetUp]
        public void TestFixtureSetUp()
        {
 
            // Initialize the settings
            Settings mySettings = new Settings();
 
            // Set the default browser
            mySettings.Web.DefaultBrowser = BrowserType.FireFox;
 
            // Create the manager object
            myManager = new Manager(mySettings);
 
            // Start the manager
            myManager.Start();
 
            
 
        }
         
        [Test]
        public void Kendo()
        {
 
            myManager.LaunchNewBrowser();
 
            myManager.ActiveBrowser.NavigateTo("http://demos.kendoui.com/web/numerictextbox/events.html");
 
            System.Threading.Thread.Sleep(5000);
 
            myManager.ActiveBrowser.RefreshDomTree();
 
            KendoInput textBox = myManager.ActiveBrowser.Find.ByExpression<KendoInput>("class=k-widget k-numerictextbox");
 
            textBox.TypeText("50");
        }
 
        [TearDown]
        public void TearDown()
        {
            // Shut-down the manager and do all clean-up
            myManager.Dispose();
        }
 
    }

Every time it runs (KendoInput textBox = myManager.ActiveBrowser.Find.ByExpression<KendoInput>("class=k-widget k-numerictextbox");) this  returns null. I have tried many many things changing DomRefreshTree, waiting for element, longer thread.sleep (terrible solution). Ive tried to intialize the object as so(KendoInput textBox = new  KendoInput).What could be the issue?  Ive ran it at least 40 times and only one time did it actually find the object.  Ive attached the solution. In all the other threads with this problem your support staff runs peoples project and says it works. I am looking for a reason this may be happening and a possible solution.

 

thanks

7 Answers, 1 is accepted

Sort by
0
Jared
Top achievements
Rank 1
answered on 02 Sep 2015, 05:39 PM
Also can you send me a link to ticket 870203. the one post said there is an answer in that ticket but I cant find that ticket anywhere.
0
Jared
Top achievements
Rank 1
answered on 02 Sep 2015, 08:18 PM

Update:

 This example from your admin returns null:

KendoInput tBox = myManager.ActiveBrowser.Find.ByExpression<KendoInput>("class=k-widget k-numerictextbox");

In this example the object can be found however I would like to use the first example:

var te = myManager.ActiveBrowser.Find.ByExpression("class=k-widget k-numerictextbox");

0
Ivaylo
Telerik team
answered on 07 Sep 2015, 10:48 AM
Hello Jared,

You should look for the span instead for the input. This is due to kendo control specifics.

Here is the correct code:

KendoInput span = myManager.ActiveBrowser.Find.ByExpression<KendoInput>("class=k-widget k-numerictextbox");
Assert.IsNotNull(span);
span.TypeText("50");


Thanks for your understanding.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Jared
Top achievements
Rank 1
answered on 08 Sep 2015, 12:26 PM

Hi Ivaylo

 I have tried your suggestion and still get a null. I dont see how this is any different from what I tried other than naming the input a span instead of textbox. Everything else is the same.

 Thanks

Jared

0
Ivaylo
Telerik team
answered on 09 Sep 2015, 01:30 PM
Hello Jared,

In the project provided the class you are using was different, after I changed it the test is executing successfully. Here is a short video demonstration (no audio) on how this works on my end. In order to investigate what is causing the behavior I will need to be able to reproduce the behavior on my end.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Jared
Top achievements
Rank 1
answered on 29 Sep 2015, 08:06 PM
Thanks for all your help :)
0
Ivaylo
Telerik team
answered on 02 Oct 2015, 10:52 AM
Hello,

You are most welcome!

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Jared
Top achievements
Rank 1
Answers by
Jared
Top achievements
Rank 1
Ivaylo
Telerik team
Jared
Top achievements
Rank 1
Share this question
or