0

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

4

2 回答 2

1

You need to insert a wait in your code till everything is loaded, then you will be able to find controls.

It works in debug mode because, while debugging with breakpoints it get time things to be fully loaded.

于 2012-06-01T06:05:00.370 回答
1

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.

于 2013-05-01T16:02:08.127 回答