Volkan Posted January 13, 2021 Share Posted January 13, 2021 Hello everyone, friends. With AutoIt UI Automation, I had to delete data from an app's text box in the Nox Player emulator. That's how I did it. It seamlessly erases the space in the text box. I am concerned about whether I am doing everything right in my code. What are your ideas? Please share your suggestions with me. Best regards Thanks.. expandcollapse popup#include "..\Includes\CUIAutomation2.au3" #include "..\Includes\UIA_Functions-a.au3" Opt("MustDeclareVars", 1) Global $oUIAutomation Global $pDesktop, $oDesktop Global $pNox, $oNox Global $pNoxSub, $oNoxSub prepareNox() setVarsInit() deleteTextBox() Func prepareNox() ; Prepare Nox Player If Not WinExists("[CLASS:Qt5QWindowIcon]") Then Exit Else WinActivate("[CLASS:Qt5QWindowIcon]", "") EndIf Sleep(1000) EndFunc ;==>prepareNox Func setVarsInit() ; Create UI Automation object $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; Nox Player Element Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Qt5QWindowIcon", $pCondition0) If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) $oDesktop.FindFirst($TreeScope_Children, $pCondition0, $pNox) $oNox = ObjCreateInterface($pNox, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oNox) Then Return ConsoleWrite("$oNox ERR" & @CRLF) ConsoleWrite("$oNox OK" & @CRLF) ; Nox Sub Class element Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "subWin", $pCondition0) If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) $oNox.FindFirst($TreeScope_Descendants, $pCondition0, $pNoxSub) $oNoxSub = ObjCreateInterface($pNoxSub, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oNoxSub) Then Return ConsoleWrite("$oNoxSub ERR" & @CRLF) ConsoleWrite("$oNoxSub OK" & @CRLF) EndFunc ;==>setVarsInit Func deleteTextBox() ; Nox Alt Pencere Sınır Değişkeni Local $vsNox ; Nox Alt Penceresi $oNoxSub.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $vsNox) ; X konumunu Nox Player boyutuna göre hesapla Local $x_mat = Int($vsNox[2] / 1.95) ; Y Konumunu Nox Player boyutuna göre hesapla Local $y_mat = Int($vsNox[3] / 1.32) ; X Konumunu bul Local $x = $vsNox[0] + $vsNox[2] - $x_mat ; Y Konumunu bul Local $y = $vsNox[1] + $vsNox[3] - $y_mat ; Fare imlecini x ve y konumuna ışınla MouseMove($x, $y) ; Farenin sol tuşunu x ve y konumuna tetikle MouseClick("left") ; Uyku Sleep(500) ; Imei sil Send("{BS 20}") EndFunc ;==>deleteTextBox Link to comment Share on other sites More sharing options...
seadoggie01 Posted January 14, 2021 Share Posted January 14, 2021 (edited) Func prepareNox() ; Prepare Nox Player If Not WinExists("[CLASS:Qt5QWindowIcon]") Then Exit Local $hNox = WinActivate("[CLASS:Qt5QWindowIcon]", "") ; Instead of: Sleep(1000) WinWaitActive(hNox, "", 0) ; Optionally, add a timeout for it not to be active EndFunc ;==>prepareNox And since you're already using UI Automation, use it for setting the value of that box too. (Granted, I can't test this, so maybe your field doesn't support it) If you're using UIASpy, this example code is under Sample Code\Patterns... and Sample Code\Pattern Methods... Local $pValuePattern, $oValuePattern $oNoxSub.GetCurrentPattern($UIA_ValuePatternId, $pValuePattern) $oValuePattern = ObjCreateInterface($pValuePattern, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern) If Not IsObj($oValuePattern1) Then Return ConsoleWrite("$oValuePattern1 ERR" & @CRLF) ConsoleWrite("$oValuePattern OK" & @CRLF) Local $sValue = "" ; Set this to an empty string to clear the text $oValuePattern.SetValue($sValue) ConsoleWrite("$oValuePattern.SetValue()" & @CRLF) Edited January 14, 2021 by seadoggie01 Volkan 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Volkan Posted January 14, 2021 Author Share Posted January 14, 2021 First of all I am grateful for your advice. Yes I know the SetValue and Invoke methods. But NoxPlayer does not have access to hidden elements of any application. Of the Nox Player Class elements, I could only access "Qt5QWindowIcon" and "Qt5QWindowToolSaveBits". Note: I have used all tools like UIASpy and Microsoft Inscept.exe. Result failed. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now