PeteT
PeteT

Reputation: 19180

Attach Watin to an existing browser always times out

I am trying to attach Watin to an existing instance of Internet Explorer 9. The trouble is no matter what I try it seems to just timeout. The code I am using is:

Settings.AttachToBrowserTimeOut = 240;
Settings.WaitUntilExistsTimeOut = 240;
Settings.WaitForCompleteTimeOut = 240;   

Browser.AttachTo<IE>(Find.ByTitle("Google"), 240);

This code is what is in the Watin guide here minus the timeout adjustments I have tried. I have also tried setting the code to run x86 not any cpu but still not working. Any ideas what I am doing wrong.

Upvotes: 2

Views: 2489

Answers (1)

t3hn00b
t3hn00b

Reputation: 912

The method you write in is missing the single threaded ApartmentState. The easiest way to fix this is to add [STAThread] above the method where you're trying to use that code.

For example this:

//[STAThread]
static void Main(string[] args)
{
    IE.AttachTo<IE>(Find.ByTitle("Google"), 5);
}

acts like you described. When you uncomment the [STAThread]

[STAThread]
static void Main(string[] args)
{
    IE.AttachTo<IE>(Find.ByTitle("Google"), 5);
}

it works as intented.

Upvotes: 2

Related Questions