Jump to content

Recommended Posts

Posted (edited)

Hi everybody,

i need to automate a .Net Window. Therefore i have to click a few Buttons and check if a Window exists.

Unfortunately is Invoke() on a Object a "modal hanging type". After ~10sec the process kills themselve. But i won't wait so long.

Is there a different method to click a .Net Button?

error handling is deleted in the demo scriptblock

$oUIAutomation1 = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
    $oUIAutomation1.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    $oUIAutomation1.CreatePropertyCondition( $UIA_NamePropertyId, $PAVeTitle, $pCondition ) ; Window Title
    $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pPAVe)
    $oPAVe_Main = ObjCreateInterface($pPAVe, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    $oUIAutomation1.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeID, $pCondition3 )
    $oUIAutomation1.CreatePropertyCondition( $UIA_NamePropertyId, $ButtonName, $pCondition4 )
    $oUIAutomation1.CreateAndCondition($pCondition3, $pCondition4, $pAndCondition34)
    $oPAVe_Main.FindFirst( $TreeScope_Descendants, $pAndCondition34, $pButton2 )
    $oButton2 = ObjCreateInterface( $pButton2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    $oButton2.GetCurrentPattern($UIA_InvokePatternId, $pInvoke)
    $oInvoke = ObjCreateInterface($pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern)
    $oInvoke.Invoke()

Meanwhile i found the Func UIA_MouseClick( $oObject )

$oUIAutomation1 = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
    $oUIAutomation1.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    $oUIAutomation1.CreatePropertyCondition( $UIA_NamePropertyId, $PAVeTitle, $pCondition ) ; Window Title
    $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pPAVe)
    $oPAVe_Main = ObjCreateInterface($pPAVe, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    $oUIAutomation1.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeID, $pCondition3 )
    $oUIAutomation1.CreatePropertyCondition( $UIA_NamePropertyId, $ButtonName, $pCondition4 )
    $oUIAutomation1.CreateAndCondition($pCondition3, $pCondition4, $pAndCondition34)
    $oPAVe_Main.FindFirst( $TreeScope_Descendants, $pAndCondition34, $pButton2 )
    $oButton2 = ObjCreateInterface( $pButton2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    UIA_MouseClick($oButton2)

This Function only activates the target window but click not the Button

i found it on my own. Thread closed.

Edited by Schnuffel
Thread closed
The two basic principles of Windows system administration:
For minor problems, reboot -- For major problems, reinstall
"Sarkasm is the lowest form of humor, but the highest form of intelligenz"
Val McDermid
 
no advertising:
If you want to translate your texts into another language,
I can only recommend deepl.com. I am very satisfied with the translations.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...