Jump to content

Recommended Posts

Posted

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")
 

3.png

4.png

Posted

@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.

Posted (edited)

yeah, native AutoIt does not work on WPF apps. the ui stuff does as mentioned by subz

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted (edited)

 

$result = ControlGetText("Calculator","","Static4")

#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 by ad777

none

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...