Search code examples
c#internet-explorerc#-4.0watin

WatiN can't find element by alt


I have a page that has the following line of code

<INPUT border=0 type=image alt="Use a password" name="SUBMIT-password.pss" src="docs/pics/en-us/useapassword_button.jpg">

My code is

using (var browser = new IE(path)) 
{
browser.Button(Find.ByAlt("Use a password")).Click();
Assert.IsTrue(browser.ContainsText("WatiN")); 
}

Solution

  • Instead of browser.Button, use browser.Image

    I setup a test file with your HTML snippet and the following works as you'd expect. If I'm remembering correctly, in WatiN 1.? you'd use Button, but in WatiN 2.1 you use the Image class.

    Console.WriteLine(browser.Image(Find.ByAlt("Use a password")).Name);
    

    The above is tested on WatiN 2.1, IE9, Win7.