c# - UIAutomation Click button without making window take focus and GetCurrentPattern() returning unsupported pattern -


i have handle of window , want click it's button named "load settings". have 2 problems.

  • my first problem when call invoke on invokepattern, brings window focus , undesirable application.
  • my second problem visible , documented in comments towards end of following code:

    automationelement aebot = automationelement.fromhandle(mbotsettinglist.elementat(i).getwindowhandle()); automationelement aebuttonloadsettings = aebot.findfirst(treescope.children, new propertycondition(automationelement.nameproperty, "load settings")); invokepattern ipclickloadsettings = (invokepattern)aebuttonloadsettings.getcurrentpattern(invokepattern.pattern); thread invokeloadsettingsthread = new thread(ipclickloadsettings.invoke); invokepattern ipclickopen = null; automationelement aeopendialogedit = null; automationelement aebuttonopen = null; automationelementcollection aedialogs = null; automationelement aeopendialog = null; valuepattern vpopendialogedit = null;  //using thread invoke load settings button click because result of clicking load settings dialog opened , invoke doesnt return nealy 10 seconds invokeloadsettingsthread.start(); //we wont join() thread because goes on far longer expect in function  //get collection of dialog windows direct children of main window have handle aedialogs = aebot.findall(treescope.children, new propertycondition(automationelement.classnameproperty, "#32770"));  while (aedialogs.count == 0) {     //this while loop continue check open file dialog may take little time open     aedialogs = aebot.findall(treescope.children, new propertycondition(automationelement.classnameproperty, "#32770"));     thread.sleep(250); }  (int j = 0; j < aedialogs.count; j++) {     //there 1 child dialog window, make sure have correct 1     if (aedialogs[j].current.name == "open")     {         debug.writeline("found open dialog!");         aeopendialog = aedialogs[j];         break;     } }  //inside open window, first edit window 1 file name/path should entered aeopendialogedit = aeopendialog.findfirst(treescope.descendants, new propertycondition(automationelement.classnameproperty, "edit"));  //set value of file name/path string variable "loadsettingsstring" vpopendialogedit = (valuepattern)aeopendialogedit.getcurrentpattern(valuepattern.pattern);  vpopendialogedit.setvalue(loadsettingsstring);  //******************************************problem begining below******************************************  //using multiple methods, can successful automationelement "open" button in open file dialog aebuttonopen = aeopendialog.findfirst(treescope.subtree, new propertycondition(automationelement.nameproperty, "open"));  //aebuttonopen = aeopendialog.findfirst(treescope.subtree, new propertycondition(automationelement.nameproperty, "cancel")); //something consider: if assigned aebuttonopen automationelement find looking "cancel" rather "open"  debug.writeline(aebuttonopen.current.name + " button found!"); //prints "open button found!" //if aebuttonopen assigned "cancel", print "cancel button found!"  ipclickopen = (invokepattern)aebuttonopen.getcurrentpattern(invokepattern.pattern); //getcurrentpattern has returned null //if aebuttonopen assigned "cancel", not null  ipclickopen.invoke(); //invoke() on null results in "unsupported pattern" exception //if aebuttonopen assigned "cancel", work , open file dialog exited if cancel clicked 

use uiaverify @ uia tree of application. looking @ code, suspect you're not retrieving element think are. if 'open' element button, should support invoke pattern.

alternatively, opening dialog , searching sub element of dialog. possible running reliability issue here uia tree still being created dialog. check this, add sleep 1 second , see if resolves issue. if case, uia structure changed events. events let synchronize uia test code against changes in uia tree.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -