Object Reference Exception in WebTestingAutomationSample

Bug reports.
sgniile
Posts: 3
Joined: Thu Oct 23, 2008 2:06 pm

Object Reference Exception in WebTestingAutomationSample

Post by sgniile » Thu Oct 23, 2008 2:21 pm

I am getting an exception running the WebTestingAutomationSample in the Ranorex Studio.


I have also tried running the code within Visual Studio 2008 ( after copying and converting to a VS2008 project) and I get the same exception at the same point.

It fails on running the ToString() method of the InnerHtml property of the WebElement.

If I debug in VS2008 I am able to call the ToString() method without an exception.

If I remove the ToString() method from the InnderHTML property and run the sample, I no longer get the exception, but the InnerHTML property doesn't return anything to the logger, even though it is supposed to return a string.

Can you help?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Oct 23, 2008 3:57 pm

You are right, the InnerHtml property should not be null in the example. Indeed, when I run the example on my computer, the property is not null.

Do you always experience this problem, i.e. in every test run?
What version of Internet Explorer do you have?

Regards,
Alex
Ranorex Support Team

sgniile
Posts: 3
Joined: Thu Oct 23, 2008 2:06 pm

Post by sgniile » Fri Oct 24, 2008 6:08 pm

I experience this problem on every test run.

I am running IE7.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Oct 27, 2008 9:24 am

Perhaps this is some timing issue. Could you please insert the following line

Code: Select all

System.Threading.Thread.Sleep(5000);
for testing purposes?
Insert the code right before these two lines:

Code: Select all

WebElement ajaxOutput = exampleDoc.FindDiv("ajax_out");
Logger.Info("Ajax content read successfully: " + ajaxOutput.InnerHtml.ToString());
Regards,
Alex
Ranorex Support Team

sgniile
Posts: 3
Joined: Thu Oct 23, 2008 2:06 pm

Post by sgniile » Mon Oct 27, 2008 4:02 pm

It works when I add the thread sleep as per your instructions.

I then tried reducing the sleep time and found that
System.Threading.Thread.Sleep(140);
works

but
System.Threading.Thread.Sleep(135);
fails

I also tried changing the wait value in the line just prior but that did not work, see below.

// Wait for loading ajax content...
exampleDoc.WaitForDocumentLoaded(5000);//<<<<< this didn't work

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Oct 29, 2008 3:57 pm

It seems that when using Ajax updates, the WaitForDocumentLoaded()
method does not work correctly (it returns immediately). We will try to address the issue.
Please use the check for InnerHtml == null / sleep as a workaround instead.

Michael
Ranorex Team