0

I am using WatiN and I need to determine if an image has been loaded. In my case I get the red X on the page but when I use...

 var image = WebBrowser.Current.Image(imageName);
 if (!image.Exists)
   {
     Assert.Fail(string.Format("Could not find '{0}' image on the page", imageName));
   }

...the Assert doesn't fail because the name of the image does exist on the page. BUT it is not loaded.

Is there a way to use WatiN to eval with JQuery or something that tells me when I get the red X? I have tried every method and property of WebBrowser.Current.Image to no avail.

Sakamoto Kazuma
  • 2,573
  • 7
  • 34
  • 75

2 Answers2

0

If i understand correctly you are trying to find the image by name attribute. If the name attribute is "image_name_attr" (you can verify this by firebug) use this:

 WebBrowser.Current.Image(Find.ByName("image_name_attr")); //constraint

If there is a class name on the image you can use:

 WebBrowser.Current.Image(Find.ByClass("image_class_attr"));
alonp
  • 1,307
  • 2
  • 10
  • 22
  • I'm hoping for a different answer. I am trying to find the image by name and see if it is loaded. Just finding the name is not enough because the name exists in the DOM whether the image has been loaded or not. The dev team changed the path name and the path is incorrect and the page only displays a red X. – user2442005 Jun 03 '13 at 15:46
0

The Assert is not failing because WatiN is doing exactly what it should; it is checking if the image html element exists. What you need to be checking for is if whether the file exists on the server.

Take a look at this SO question/answer - I've used this approach in the past and it worked mighty fine. Test to see if an image exists in C#

Community
  • 1
  • 1
OCary
  • 3,231
  • 2
  • 16
  • 17