Unable to save the file in specified location using Autoit - selenium

Followed the below steps to save a file in desired location:
Step1: Save As window getting opened(with the default downloads location, with file name as DOC)
Step2: entering the file name as "D:\temp\sample.pdf" (which is getting entered in the edit bar)
Step3: clicking the save button (button clicked, file downloaded in the default location rather than the "D:\temp" location)
I have created an .exe with the below .au3 script
WinWait("[CLASS:#32770]","",10)
Sleep(2000)
ControlSetText("Save As", "", "Edit1", $CmdLine[1])
Sleep(5000)
ControlClick("Save As", "", "Button1");
Sleep(5000)
On clicking save, it is getting saved in the default location rather than the specified location.
The below code, executing the script.
IO.popen('autoit_script.exe D:\temp') #Ruby Code
Is there a way to sort it out?

It depends on the software you are trying to automate but usually this happens because the software is not recognizing there is a change in the file save path box. The problem is in how ControlSetText works. Try using ControlSend with some error checking to make sure the file path you are try to set is getting put in right. Sometimes you have to play with a few different variations to see what works with the software you are automating. Here are two examples you can try:
Example one:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
ControlSetText($hWin, "", "Edit1", $CmdLine[1]) ;set text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", "{ENTER}")) ;should work like click button 1 but you will have to check
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf
Example two:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
While 1
ControlSetText($hWin, "", "Edit1", "") ;just makes sure there is no text in the control text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", $CmdLine[1])) ;set text using ControlSend
If ControlGetText($hWin, "", "Edit1") = $CmdLine[1] Then ExitLoop ;makes sure that the control got ALL of the text before exiting loop
WEnd
ControlClick($hWin, "", "Button1");
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf

Related

Getting value from text box in SAP application custom container

My requirement is to automate SAP flow using AutoIt. When I am trying to get the values(test) from below username textbox it is not getting the text box value and displaying an empty value. I want to get the value from the text box and I need to compare with string. Could you please help me out?
Output :
I already referred below links :
https://www.autoitscript.com/autoit3/docs/functions/ControlGetText.html
https://www.autoitscript.com/forum/topic/177533-get-text-from-a-button/
https://www.autoitscript.com/forum/topic/116065-get-text-from-active-window/
A screenshot of AutoIt finder tool :
My AutoIt code :
Run("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")
Local $hWnd = WinWaitActive("SAP Logon 740")
WinSetState($hWnd, "", #SW_MAXIMIZE)
ControlFocus("SAP Logon 740","","SAPTreeList1")
ControlTreeView("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","Expand","#0")
ControlClick("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","left",2,47,60)
Sleep(2000)
ControlClick("SAP Logon 740","","[CLASS:SAPTreeList; INSTANCE:1]","left",2,59,115)
Sleep(2000)
ControlClick("SAP Logon 740","","[CLASS:SysListView32; INSTANCE:1]","left",1,71,573)
Sleep(1000)
ControlClick("SAP Logon 740","","Log &On")
Sleep(3000)
Local $hNewWnd = WinWaitActive("SAP")
; Retrieve the classlist of the Notepad window using the handle returned by WinWait.
Local $sClassList = WinGetClassList("SAP")
#ConsoleWrite($sClassList)
; Display the classlist.
Sleep(3000)
ControlClick("SAP","","","left",1,179,56)
# MsgBox(0, "output", $sClassList)
Send("test")
Sleep(1000)
$wrd = ControlGetText("SAP","test","")
MsgBox(0,"Display",$wrd)
Control tab :
Please read about this and this.
#RequireAdmin ;sometimes this is required in order to be able to manipulate windows
Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
$wrd = ControlGetText("[TITLE:SAP]","",100);100 is id from the WindowInfo Tool
If #error Then $wrd = ControlGetText("[TITLE:SAP]","","[CLASS:Afx:68570000:1008; INSTANCE: 1]")
;This is the advanced method. Aslo shown in the WIndowInfo Tool.
MsgBox(0,"Display",$wrd)

Error - Unexpected } at the end of While Loop

I'm using while true loop to constantly check run this script. After adding the if expression with whitelist ahk gives an error about unexpected } at the end of code. As far as I know there should be }.
Using Loop command gives the same error.
Removing the problematic } at the end causes the code running in background but not doing anything.
;Setup
Sleep, 1000
whiteList = "none"
;Main Loop
While True
{
siteName = YouTube
WinGetActiveTitle, tabName
Sleep, 10000
if tabName = %whiteList%{
Continue
}
;If current website is Youtube, ask if am I supposted to be here
if InStr(tabName, siteName){
Sleep, 10000
MsgBox, 292, Reality Check, Should you do this?
IfMsgBox, Yes
{
whiteList = tabName
}
;Close tab in mozilla
else
{
WinActivate, %tabName%
Sleep, 10
Send ^w
}
}
}
Code is unfinished, It should run in background and when the user is using YouTube fore some time it should ask him whether is he supposted to watch Youtube.
If he clicks yes, the program should ignore that specific page.
Else it should close it.
The % around the whiteList-var shouldn't be there. When I wrote it like below it seems to work:
if tabName = whiteList
Continue
Also the whiteList = tabName will just assign the string "tabName" to whiteList. Use whiteList := tabName for assigning, and if var1 = var2 for comparison.

Create general purpose WinWaitActive in AutoIT

I'm thinking of using the WinWaitActive function to play a sound file every time the currently active program finished a task (ie. After Effect finished rendering, Word finished saving, etc.).
From what I know about WinWaitActive, I'll need to write a script for each internal process of each application. That's a huge amount of automation scripts. Is there any way to make a single script that will work with all programs and processes?
Try something like this:
#include<array.au3>
Global $window_Array[1]
$window = "dokument - wordpad"
checkWin()
;ConsoleWrite(_ArrayToString($window_Array, #CR))
Func checkWin()
Global $var = WinList()
For $i = 1 To $var[0][0]
If $var[$i][0] <> "" Then _ArrayAdd($window_Array, $var[$i][0])
Next
If _ArraySearch($window_Array, $window, 0, 0, 0) <> - 1 Then
MsgBox(0, "", "Found!")
Else
MsgBox(0, "", "Not Found!")
EndIf
EndFunc ;==>checkWin

checking a line of code in a file on quickbasic

I'm trying to make my program have a dialogue box with a password that has been set in a file. I need help having it scan a line of code in a file and if the password entry is true, then proceed.
This code gets a password and compares it to a password in a file:
INPUT "Password", x$
OPEN "password.dat" FOR INPUT AS #1
INPUT #1, y$
IF x$ = y$ THEN PRINT "Match": ' do stuff

AutoIt: run a program selected with FileOpenDialog?

I need to make a script that allows a user to run a software with certain parameters (that should be typed in). So, first step, select the exe. Second, a text input box should allow the user to enter the parameters. I can't get the first step done.
I tried with the second example found here: FileOpenDialog
The only modification is a Run command I added. When I run the script, I see the complete file path for the executable but nothing runs. I don't see an error either:
include <FileConstants.au3>
include <MsgBoxConstants.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select a single file of any type."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, #WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
If #error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
Else
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
; Replace instances of "|" with #CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", #CRLF)
; Display the selected file.
MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & #CRLF & $sFileOpenDialog)
Run($sFileOpenDialog)
EndIf
EndFunc ;==>Example
#include <FileConstants.au3>
Example()
Func Example()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select a single file of any type."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, #WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
If #error Then
; Display the error message.
MsgBox(1, "", "No file was selected.")
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
Else
; Change the working directory (#WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(#ScriptDir)
; Replace instances of "|" with #CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", #CRLF)
; Display the selected file.
MsgBox(1, "", "You chose the following file:" & #CRLF & $sFileOpenDialog)
Run($sFileOpenDialog)
EndIf
EndFunc ;==>Example
This works for me.
I dont know this "include MsgBoxConstants.au3" wich i think is unnecessary.
Lg Teifun2
You need to add the # before the include. Also the 2nd include has to be Constants.au3. When I do these changes I can successfully start any application with your code.
#include <FileConstants.au3>
#include <Constants.au3>