It is possible that the IE instance isn't being disposed properly. You'll want to check Task Manager and see how many open IEXPLORE.EXE processes you have running. If you have more than two, I would suggest implementing a using block and then checking Task Manager again:
using (IE ie = new IE(URLs.mainURL)
{
...
}
An even better solution would be to use the AttachTo method once you have initialized a "master" browser instance variable:
private IE ie = new IE();
public void btnStartBrowsing_Click(object sender, EventArgs e)
{
using ie2 = ie.AttachTo<IE>(Find.ByUrl(URLs.mainURL))
{
...
}
}
UPDATE:
Since you need access to the browser for the duration of the session, I would strongly suggest using a singleton object to house the browser object:
public sealed class BrowserIE
{
static readonly IE _Instance = new IE();
static BrowserIE()
{
}
BrowserIE()
{
}
public static IE Instance
{
get { return _Instance; }
}
}
The browser is only opened one time, and you have access to it whenever you need it, since you don't have to manually instantiate it. To use it, you simply call the Instance property every time you need access to the browser:
BrowserIE.Instance.GoTo(URLs.mainURL);
Divs headerDivs = BrowserIE.Instance.Divs.Filter(Find.ByClass("header"));