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)
Related
I'm new to DXL programming language in IBM DOORS. However, I think I have managed to do many interesting things: create Modules, create Objects, create Links, delete Objects etc.
However, I have a very specific problem regarding "null" Modules. I've just written null between "" because the modules exist and they are referenced with a correct name.
When doing this:
Module m1 = edit("1. MY_MODULE", false)
save(m1)
close(m1)
An error like this appears:
enter image description here
You could not understand what does that mean as it is spanish. Basically states this: "Module null parameter in the first position of the argument." That means that the "m1" is null, as the parameter for save() method is null.
The point is that it is an error which appears only sometimes. It seems that the Module is null as it has been previously opened and DOORS does not close properly.
Is there any way, any method...whatever to avoid this error?
I assume that the script cannot find the module when another folder is active.
Try
Module m1 = edit ("/myproject/myfolder/mysubfolder/1. MY_MODULE", false)
There might be many reasons that the module can't be opened in edit mode. For example: User do not have write access OR Module is being used by other user, etc.
However, you can get around the error with the below code snippet:
Module m = edit('My_module', false)
if(!null m) {
//execute program
...
}
else {
//do something
}
I hope this helps.
How does your script work? do you open the same module again and again and sometimes get the error or do you open lots of modules and for some of them it works and for others it doesn't? In the latter case, perhaps you misspelled the path. You could add some sanity checks like
string fullPathToMod = "/myproject/myfolder.."
Item i = item fullPathToMod;
if null i then error "there is no item called " fullPathToMod
if "Module" != type i then error "there is an item, but it's not a module, it's a " type i
This is how the Code is structured:
void checkModule(string folderPath, string mName, Skip list, int listSize, int listLastIndex, string headers[], string heading[], string headerKey, bool uniqueKey, string combinedKey[]){
if (module mName){
Folder f = folder(folderPath)
current = f
Module m = edit(folderPath""mName, false)
current = m
Object o = first(m) // error sometimes: Se ha pasado un parametro Module null en una posiciĆ³n de argumento 1
if (o == null){
loadModule(m, list, listSize, listLastIndex, headers, heading)
} else {
updateModule(m, mName, list, listSize, listLastIndex, heading, headerKey, headers, uniqueKey, combinedKey)
save(m)
close(m)
}
if (lastError() != ""){
print "Error: " lastError() "\n"
}
} else {
print "No module " mName ".\n"
}
}
Exactly it breaks in line:
current = m
But as said, only sometimes, not always.
BTW, I'm executing this script via Batch, via Java code. One curious thing is that if I close DOORS, and execute the script it does execute correctly. It is as if it needs to be closed in order to edit modules correctly.
I pressume current can be used more than once with different types of Items. I guess it should not be wrong, but it breaks saying (more or less):
Null value passed to DXL commmand (current Module).
Obviously, it means that m is null, but I cannot see any reason for that.
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
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
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>
I tried to implement a save-as-ftp button in Rebol embedded editor. Implementation of the save-as-button is this:
save-as-ftp: has [file-content][
file-content: t1/text
prefs-file: rejoin [_self-path %ftp.preferences.txt]
either exists? prefs-file [
prefs-ftp: construct load prefs-file; see article application configuration file
user: prefs-ftp/user
password: prefs-ftp/password
server-path: prefs-ftp/server-path
][
user: ask "User: "
password: ask/hide "Password: "
server-path: ask "Server-Path: "
]
view ftp-view: layout [
origin 10x10 space 8x4
style btn btn 140
ftp-field: text bold "" 140 center
pad 0x4
btn-enter 140 "Save" #"s" [hide-popup result: ftp-field/text]
btn red + 50 "Quit - No Save" [hide-popup quit-now]
]
file-target: result
ftp-target: rejoin [ftp:// user ":" password "#" server-path file-target]
write ftp-target file-content
print ["uploaded" file-target "to" rejoin [ftp:// "XXXXXXX" ":" "XXXXXXX" "#" server-path]]
true
]
My problem is with view ftp-view : I cannot even type in ftp-field text box as the popup window loses focus.
hide-popup is used to close a modal window.
A modal window is opened by using 'inform
I don't see any modal windows here.
Oh .. this is a button or something that you are attaching to the rebol editor?
I modified mine some years ago to edit ftp files ... I'll have to see if I can find what I did.