Word Document Control Automation in WPF Application


  • Hi All,

    A word document control is embedded in WPF application and its content is visible for editing and reading. I am trying to automate this control but facing issue as elucidated below

    I am making use of UI Automation API to automate WPF control in Coded UI Test and code to automate above scenario as follows

    AutomationElement applicationElement=<application Element assingned here>

    AutomationElement wordElement=applicationElement.FindFirst(TreeScope.Descendants, new System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty,"Microsoft Word Document"));

    Object objWordCtrl=wordElement;

    Microsoft.office.Interop.Word.Document worddoc=(Microsoft.office.interop.Word.Document) wordElement;

    But I am getting expection error saying unable to cast object of type 'System.Windows.Automation.AutomationElement' to type 'Microsoft.office.Interop.word.Document'

    Can you please help me on above error so that i can make use of word API to act on word document.

    Tuesday, February 28, 2012 4:46 AM

All replies