Reputation: 1017
I am getting this error when performing browser automation using WatiN.
I am using this solution from a previous thread in order to acess the Save As dialog
The code fails at the following line of the DownloadIeFile method.
AutomationElementCollection dialogElements = AutomationElement.FromHandle(windowDialog.Hwnd).FindAll(TreeScope.Children, Condition.TrueCondition);
What's bizarre is that the code runs fine if there was already an instance of IE open on the machine. I have tried emulating this by:
1] create instance of a temporary browser
2] create browser object
for manipulation
3] close both browser instances.s.
and this also fails.
FYI this is the code I am using:
class UpdateDiaryFigures
{
public static void Start()
{
System.Threading.Thread.Sleep(1000);
IE browser = new IE("http://www.example.com");
//browser.Visible = false;
Login(browser);
string test = GetExport(browser, "AgentOpen", "01/10/2014", DateTime.Today.ToString("dd/MM/yyyy"), "Agent Name Ltd");
//browser.Dispose();
}
static string GetExport(IE browser, string exportName, string fromDate, string toDate, string ddlValue)
{
browser.GoTo("http://www.example.com/ExcelExport.aspx");
string open = "";
switch (exportName)
{
case "AgentOpen":
case "AgentClosed":
if (exportName == "AgentClosed") { open = "Yes"; } else { open = "No"; }
browser.TextField(Find.ById("txtAgentFromDate")).Value = fromDate;
browser.TextField(Find.ById("txtAgentToDate")).Value = toDate;
browser.SelectList(Find.ById("cboAgentCleared")).Select(open);
browser.SelectList(Find.ById("cboAgent")).Select(ddlValue);
browser.Image(Find.ById("btnPrintAgentRpt")).Click();
break;
case "AllAgentOpen":
break;
case "AllAgentClosed":
break;
case "CourtOpen":
case "CourtClosed":
break;
}
string filename = @"c:\Downloads\" + exportName
browser.DownloadIeFile(filename);
return filename;
}
static void Login(IE browser)
{
browser.TextField(Find.ByName("ctl00$cphMainContent$txtCompanyID")).Value = "ID";
browser.TextField(Find.ByName("ctl00$cphMainContent$txtUserID")).Value = "user";
browser.TextField(Find.ByName("ctl00$cphMainContent$txtPassword")).Value = "pass";
browser.Button(Find.ByName("ctl00$cphMainContent$btnLogin")).Click();
}
}
Upvotes: 1
Views: 1531
Reputation: 698
You may have multiple iexplore.exe process running even if you can only see one IE window. For example iexplore.exe and iexplore.exe*32
Upvotes: 1