Kanako Posted December 6, 2021 Share Posted December 6, 2021 please help me, i try to get the result from calculator but it's not working, it's not some kind of error, just only didn't show the result from app i think my problem with the code $result = ControlGetText("Calculator","","Static5") below is my whole code: #include<File.au3> $fileInput = FileOpen("D:\input.txt",0) $fileOutput = FileOpen("D:\output.txt",1) Run("calc.exe") ;chay app calc WinActivate("Calculator") Sleep(500) for $i=1 to _FileCountLines($fileInput) $line= FileReadLine($fileInput,$i) AutoItSetOption("SendKeyDelay",200) Send(StringMid($line, 1,1)) $operate=StringMid($line, 2,1) ;Autoit ko hieu dau + nen phai convert (+) if(StringCompare($operate,"+",0)) Then Send(StringMid($line, 2,1)) Else Send("{+}") EndIf Send(StringMid($line, 3,1)) Send("=") ;truyen dau = Sleep(1000) $actualResult = StringSplit($line,"=") $result = ControlGetText("Calculator","","Static5") $out= StringTrimRight($result,1) If (StringCompare($actualResult[2],$out)) < 1 Then ;FileWriteLine($fileOutput) FileWriteLine($fileOutput,"Expected Result "&$actualResult[2]&"| Actual Result "&out&"| Pass") Else ;FileWriteLine($fileOutput) FileWriteLine($fileOutput,"Expected Result "&$actualResult[2]&"| Actual Result "&$out&"| Fail") EndIf Send("{DEL}") Next WinClose("Calculator") Link to comment Share on other sites More sharing options...
Subz Posted December 7, 2021 Share Posted December 7, 2021 For Windows Apps you would need to use IUIAutomation MS Framework Kanako 1 Link to comment Share on other sites More sharing options...
Jfish Posted December 8, 2021 Share Posted December 8, 2021 I have a calculator automation example in the book in my sig, chapter 15 that automates aspects of calculator by referencing it's controls. It uses the AU3 info tool in Scite which I think should still work for Win10. Kanako 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Subz Posted December 8, 2021 Share Posted December 8, 2021 @Jfish Windows 10 Calculator is a modern app, unlike the previous Windows 7 Calculator app. You'll find that you can't automate it using Autoit control functions. IUIAutomation does work, for modern apps, although last time I tried it was a few years back. Kanako 1 Link to comment Share on other sites More sharing options...
Jfish Posted December 8, 2021 Share Posted December 8, 2021 Ah, okay, had not delved into the new calculator. Makes sense. Kanako 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Earthshine Posted December 8, 2021 Share Posted December 8, 2021 (edited) yeah, native AutoIt does not work on WPF apps. the ui stuff does as mentioned by subz Edited December 8, 2021 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted December 8, 2021 Share Posted December 8, 2021 look here and at the examples, I am sure there is a Calc example you can learn from Using UI Automation Code in AutoIt - AutoIt Example Scripts - AutoIt Forums (autoitscript.com) My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
junkew Posted December 14, 2021 Share Posted December 14, 2021 Here is the literal example for calc, notepad and uia (for a dutch windows version) Earthshine 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ad777 Posted December 15, 2021 Share Posted December 15, 2021 (edited) $result = ControlGetText("Calculator","","Static4") expandcollapse popup#include<File.au3> #RequireAdmin $fileInput = FileOpen("D:\input.txt",0) $fileOutput = FileOpen("D:\output.txt",1) Run("calc.exe") ;chay app calc WinActivate("Calculator") Sleep(500) for $i=1 to _FileCountLines($fileInput) $line= FileReadLine($fileInput,$i) AutoItSetOption("SendKeyDelay",200) Send(StringMid($line, 1,1)) $operate=StringMid($line, 2,1) ;Autoit ko hieu dau + nen phai convert (+) if(StringCompare($operate,"+",0)) Then Send(StringMid($line, 2,1)) Else Send("{+}") EndIf Send(StringMid($line, 3,1)) Send("=") ;truyen dau = Sleep(1000) $actualResult = StringSplit($line,"=") $result = ControlGetText("Calculator","","Static4") $out= StringTrimRight($result,1) If StringCompare($actualResult[1],$out) < 1 Then ;FileWriteLine($fileOutput) ; MsgBox(0,"",$actualResult[2]) FileWriteLine($fileOutput,"Expected Result "&$actualResult[2]&"| Actual Result "&$out&"| Pass") Else ;FileWriteLine($fileOutput) ; MsgBox(0,"",$actualResult[2]) FileWriteLine($fileOutput,"Expected Result "&$actualResult[2]&"| Actual Result "&$out&"| Fail") EndIf Send("{DEL}") Next WinClose("Calculator") Edited December 15, 2021 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. 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