How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;)
-
Can Any One Help, I am trying UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) My Requirement's are mentioned below. 1) Open Outlook 2007 2) Open Inbox 3) Select first unread email. 4) Open the first unread email. 5) If there are attachements, download the attachements. 6) Select next unread email and do the same as above. I can open the OUTLOOK 2007, But I am getting NULL value while Searching Inbox using PropertyCondition.
PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
return parent.FindFirst(TreeScope.Descendants, pc);Here are the Code,
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;namespace AmmeaBahavathi
{
class OutLookUIAutomation
{
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
private const int SW_RESTORE = 9;static void Main(string\[\] args) { // look for outlook already running Process\[\] processes = Process.GetProcessesByName("outlook"); AutomationElement aeOutLook = null; Process proc1 = new Process(); if (processes.Length == 0) { // start new outlook process proc1.StartInfo.FileName = "outlook"; proc1.Start(); proc1.WaitForInputIdle(); Thread.Sleep(5000); aeOutLook = AutomationElement.FromHandle(proc1.MainWindowHandle); } else { proc1.Close(); // pull up the existing outlook window IntPtr hWnd = processes\[0\].MainWindowHandle; if (IsIconic(hWnd)) { ShowWindowAsync(hWnd, SW\_RESTORE); } SetForegroundWindow(hWnd); } if (aeOutLook != null) {
-
Can Any One Help, I am trying UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) My Requirement's are mentioned below. 1) Open Outlook 2007 2) Open Inbox 3) Select first unread email. 4) Open the first unread email. 5) If there are attachements, download the attachements. 6) Select next unread email and do the same as above. I can open the OUTLOOK 2007, But I am getting NULL value while Searching Inbox using PropertyCondition.
PropertyCondition pc = new PropertyCondition(AutomationElement.NameProperty, name);
return parent.FindFirst(TreeScope.Descendants, pc);Here are the Code,
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;namespace AmmeaBahavathi
{
class OutLookUIAutomation
{
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
private const int SW_RESTORE = 9;static void Main(string\[\] args) { // look for outlook already running Process\[\] processes = Process.GetProcessesByName("outlook"); AutomationElement aeOutLook = null; Process proc1 = new Process(); if (processes.Length == 0) { // start new outlook process proc1.StartInfo.FileName = "outlook"; proc1.Start(); proc1.WaitForInputIdle(); Thread.Sleep(5000); aeOutLook = AutomationElement.FromHandle(proc1.MainWindowHandle); } else { proc1.Close(); // pull up the existing outlook window IntPtr hWnd = processes\[0\].MainWindowHandle; if (IsIconic(hWnd)) { ShowWindowAsync(hWnd, SW\_RESTORE); } SetForegroundWindow(hWnd); } if (aeOutLook != null) {
If Outlook is running before your process starts you get into the first
else
block andaeOutlook
is never set.Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
-
If Outlook is running before your process starts you get into the first
else
block andaeOutlook
is never set.Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.