Search code examples
c#visual-studio-2008automationwatinui-automation

Watin behaviour in debug mode is different than in normal mode


Im testing the WatiN library using this simple code:

using (var browser = new IE("http://www.google.de"))
{
    browser.TextField(Find.ByName("q")).TypeText("WatiN");        
    Button btn1 = browser.Button(Find.ById("gbqfba"));
    btn1.Click();
    while (!browser.ContainsText("watin.org"))
    {
        System.Threading.Thread.Sleep( 500 );
        btn1.Click();
    }
}

Anyway it works fine when i run it in debug mode having a breakpoint somewhere, but as soon as i run in release mode it types the desired text but the button doesnt seem to be clicked, so i have the search field with the text in it, and i dont get any search results.

Any known issues about this? any Ideas?

Thank you


Solution

  • I'm a WatiN newbie, too, and it took me a while before I got this to work. First, read this solution:

    WatiN clicking a button

    You might have to try different ways of implementing the solution to get it to work for you. For example:

    First I put the line

    browserInstance.NativeDocument.Body.SetFocus(); // set focus befor u click
    

    before the "click" action, but that worked only in Debug mode (My code didn't work at all before, so getting it to work in Debug mode was progress).

    Then I put the line before each item to get it to work in Run mode:

    browserInstance = new IE(@"http://www.google.com");
    
    TextField criteria = browserInstance.TextField(tf => tf.Name == "q");
    
    browserInstance.NativeDocument.Body.SetFocus(); // set focus befor u click
    criteria.TypeText("Come Jam With Us");
    
    browserInstance.NativeDocument.Body.SetFocus(); // set focus befor u click
    browserInstance.Button(Find.ById("gbqfb")).Click();
    

    I'm not sure why this works, but I hope it helps.