Jump to content

WhatsApp Desktop Automation - (Moved)


Recommended Posts

Hi there,

 

I am kind of new at Autoit, but I have managed to make some automation using VBA for some 3 years.

I am trying to run the WhatsApp desktop, click the search button and type any contact, for example, "John"

I am getting an error, I am trying to make a condition to select the "left side" of whatsapp application, and then click the search button, which has AriaRolePropertyId "button".

 

Any help would be appreciated very much!! Thanks!!

 

Example()

Func Example()
    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation )
    If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
    ConsoleWrite( "$oUIAutomation OK" & @CRLF )

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement( $pDesktop )
    $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
    If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
    ConsoleWrite( "$oDesktop OK" & @CRLF )
    
    ; --- Find whatsapp window ---

ConsoleWrite( "--- Find whatsapp window ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "WhatsApp Web", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pDocument1, $oDocument1
$oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pDocument1 )
$oDocument1 = ObjCreateInterface( $pDocument1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oDocument1 ) Then Return ConsoleWrite( "$oDocument1 ERR" & @CRLF )
ConsoleWrite( "$oDocument1 OK" & @CRLF )


; --- Find left side window ---

ConsoleWrite( "--- Find left side window ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "side", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pCustom1, $oCustom1
$oDocument1.FindFirst( $TreeScope_Descendants, $pCondition0, $pCustom1 )
$pCustom1 = ObjCreateInterface( $pCustom1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $pCustom1 ) Then Return ConsoleWrite( "$pCustom1 ERR" & @CRLF )
ConsoleWrite( "$pCustom1 OK" & @CRLF )

; --- Find button ---

ConsoleWrite( "--- Find button ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_AriaRolePropertyId, "button", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pButton1, $oButton1
$pCustom1.FindFirst( $TreeScope_Descendants, $pCondition0, $pButton1 )
$oButton1 = ObjCreateInterface( $pButton1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oButton1 ) Then Return ConsoleWrite( "$oButton1 ERR" & @CRLF )
ConsoleWrite( "$oButton1 OK" & @CRLF )

; --- Invoke Pattern (action) Methods ---

ConsoleWrite( "--- Invoke Pattern (action) Methods ---" & @CRLF )

WinActivate("WhatsApp")
$oButton1.Invoke()
ConsoleWrite( "$oInvokePattern.Invoke()" & @CRLF )

EndFunc

 

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi there,

 

I am kind of new at Autoit, but I have managed to make some automation using VBA for some 3 years.

I am trying to run the WhatsApp desktop, click the search button and type any contact, for example, "John"

I am getting an error, I am trying to make a condition to select the "left side" of whatsapp application, which has an automationid called "side".

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code
;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code

#include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder

Opt( "MustDeclareVars", 1 )

example()

func example()

    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation )
    If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
    ConsoleWrite( "$oUIAutomation OK" & @CRLF )

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement( $pDesktop )
    $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
    If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
    ConsoleWrite( "$oDesktop OK" & @CRLF )

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "WhatsApp", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pPane1, $oPane1
$oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pPane1 )
$oPane1 = ObjCreateInterface( $pPane1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oPane1 ) Then Return ConsoleWrite( "$oPane1 ERR" & @CRLF )
ConsoleWrite( "$oPane1 OK" & @CRLF )

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "WhatsApp Web", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pDocument1, $oDocument1
$oPane1.FindFirst( $TreeScope_Descendants, $pCondition0, $pDocument1 )
$oDocument1 = ObjCreateInterface( $pDocument1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oDocument1 ) Then Return ConsoleWrite( "$oDocument1 ERR" & @CRLF )
ConsoleWrite( "$oDocument1 OK" & @CRLF )

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_ProcessIdPropertyId, 13120, $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pCustom1, $oCustom1
$oDocument1.FindFirst( $TreeScope_Descendants, $pCondition0, $pCustom1 )
$oCustom1 = ObjCreateInterface( $pCustom1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oCustom1 ) Then Return ConsoleWrite( "$oCustom1 ERR" & @CRLF )
ConsoleWrite( "$oCustom1 OK" & @CRLF )

; --- Find window/control ---

ConsoleWrite( "--- Find window/control ---" & @CRLF )

Local $pCondition0
$oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "side", $pCondition0 )
If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
ConsoleWrite( "$pCondition0 OK" & @CRLF )

Local $pCustom2, $oCustom2
$oCustom1.FindFirst( $TreeScope_Descendants, $pCondition0, $pCustom2 )
$oCustom2 = ObjCreateInterface( $pCustom2, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
If Not IsObj( $oCustom2 ) Then Return ConsoleWrite( "$oCustom2 ERR" & @CRLF )
ConsoleWrite( "$oCustom2 OK" & @CRLF )

EndFunc

Any help would be appreciated very much!! Thanks!!

Link to comment
Share on other sites

  • Developers

Please do not create another topic when the original was moved to the correct place.

*Merged*

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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