c# - UI automation for office 2013 -


i need automate pressing file->info->"check issues" in office 2013. managed press file button code:

automationelement window = automationelement.fromhandle(window.handle); automationelementcollection buttons = window.findall(treescope.descendants, new propertycondition( automationelement.controltypeproperty, controltype.button)); automationelement file=buttons.cast<automationelement>().firstordefault(x => x.current.name == "file tab"); invokepattern ipclickloadsettings = (invokepattern)file.getcurrentpattern(invokepattern.pattern); ipclickloadsettings.invoke(); 

how can press "check issues" button or other button in info window?

thanks

i took @ word 2013 ui using inspect sdk tool, , shows related ui can programmatically invoked through uia invoke pattern, can't. instead, other ui needs selected or expanded. wrote test code below following...

  1. invoke file tab.
  2. select info item.
  3. expand check issues ui.
  4. invoke check accessibility button.

while code makes few assumptions, (and work in english builds of word,) seemed able invoke check accessibility ui ok.

for test, used unmanaged uia api comes windows, rather managed .net uia api. call windows uia api c# code using wrapper generated tlbimp.exe tool.

this did generate wrapper...

"c:\program files (x86)\microsoft sdks\windows\v10.0a\bin\netfx 4.6 tools\x64\tlbimp.exe" c:\windows\system32\uiautomationcore.dll /out:interop.uiautomationcore.dll

if steps ones below don't work you, let me know , can it.

thanks,

guy

iuiautomation uiautomation = new cuiautomation8();  iuiautomationelement rootelement = uiautomation.getrootelement();  // assume first child of root element classname of  // "opusapp" word window we're interested in. int propertyidclassname = 30012; // uia_classnamepropertyid  iuiautomationcondition conditionwordapp =     uiautomation.createpropertycondition(         propertyidclassname, "opusapp");  iuiautomationelement wordelement =     rootelement.findfirst(         treescope.treescope_children,         conditionwordapp);  // find file tab beneath word element. use automationid  // find button rather name, because automationid  // not localized. int propertyautomationid = 30011; // uia_automationidpropertyid  iuiautomationcondition conditionfiletab =     uiautomation.createpropertycondition(         propertyautomationid,         "filetabbutton");  // cache invoke pattern when filetab element,  // don't have make cross-process call later  // pattern. int patternidinvoke = 10000; // uia_invokepatternid iuiautomationcacherequest cacherequestinvokepattern =      uiautomation.createcacherequest(); cacherequestinvokepattern.addpattern(patternidinvoke);  iuiautomationelement filetabelement =     wordelement.findfirstbuildcache(         treescope.treescope_descendants,         conditionfiletab,         cacherequestinvokepattern);  // invoke tab. iuiautomationinvokepattern invokepatternfiletab =      filetabelement.getcachedpattern(patternidinvoke); invokepatternfiletab.invoke();  // note when making calls this, may necessary  // thread.sleep() short time here, give target app chance  // create , show ui being invoked.  // find info item. unfortunately item has no automationid,  // use other properties find it. test, use  // localizable name , controltype. (so means code won't  // work non-english builds of word.)  int propertyidname = 30005; // uia_namepropertyid  iuiautomationcondition conditioninfoitemname =     uiautomation.createpropertycondition(         propertyidname, "info");  iuiautomationcondition conditioninfoitemclassname =     uiautomation.createpropertycondition(         propertyidclassname, "netuiribbontab");  iuiautomationcondition conditioninfoitem = uiautomation.createandcondition(     conditioninfoitemname, conditioninfoitemclassname);  int patternidselectionitem = 10010; // uia_selectionitempatternid  iuiautomationcacherequest cacherequestselectionitempattern =      uiautomation.createcacherequest(); cacherequestselectionitempattern.addpattern(patternidselectionitem);  iuiautomationelement infoitemelement =     wordelement.findfirstbuildcache(         treescope.treescope_descendants,         conditioninfoitem,         cacherequestselectionitempattern);  // select info item, show "check issues" ui. iuiautomationselectionitempattern selectionitempatterninfoitem =      infoitemelement.getcachedpattern(patternidselectionitem); selectionitempatterninfoitem.select();  // find "check issues" element. element has no // automationid, search name , classname again. iuiautomationcondition conditioninfocheckforissuesname =     uiautomation.createpropertycondition(         propertyidname, "check issues");  iuiautomationcondition conditioncheckforissuesclassname =     uiautomation.createpropertycondition(         propertyidclassname, "netuianchor");  iuiautomationcondition conditioncheckforissues =      uiautomation.createandcondition(         conditioninfocheckforissuesname, conditioncheckforissuesclassname);  int patternidexpandcollapse = 10005; // uia_expandcollapsepatternid  // expand "check issues" ui, show "check accessibility"  // button. iuiautomationcacherequest cacherequestexpandcollapsepattern =      uiautomation.createcacherequest(); cacherequestexpandcollapsepattern.addpattern(patternidexpandcollapse);  iuiautomationelement checkforissueselement =     wordelement.findfirstbuildcache(         treescope.treescope_descendants,         conditioncheckforissues,         cacherequestexpandcollapsepattern);  iuiautomationexpandcollapsepattern expandcollapsepatterncheckforissues =      checkforissueselement.getcachedpattern(patternidexpandcollapse); expandcollapsepatterncheckforissues.expand();  // find "check accessibility" element. element has no // automationid, once again, search name , classname. iuiautomationcondition conditioninfocheckaccessibilityname =     uiautomation.createpropertycondition(         propertyidname, "check accessibility");  iuiautomationcondition conditioncheckaccessibiltyclassname =     uiautomation.createpropertycondition(         propertyidclassname, "netuitwbtnmenuitem");  iuiautomationcondition conditioncheckaccessibility =      uiautomation.createandcondition(         conditioninfocheckaccessibilityname,          conditioncheckaccessibiltyclassname);  iuiautomationelement checkaccessibilityelement =     wordelement.findfirstbuildcache(         treescope.treescope_descendants,         conditioncheckaccessibility,         cacherequestinvokepattern);  // invoke element check document's accessibility. iuiautomationinvokepattern invokepatterncheckaccessibility =     checkaccessibilityelement.getcachedpattern(patternidinvoke); invokepatterncheckaccessibility.invoke(); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -