Sankesh Posted February 26, 2019 Share Posted February 26, 2019 Hi, I am trying to pick few parameters like Username,Password,DB name from xml to autoIT script for windows software installation. can i have sample script of how to pass those parameters? Link to comment Share on other sites More sharing options...
LukeLe Posted February 26, 2019 Share Posted February 26, 2019 Hi @Sankesh, welcome to autoIT forum! Have you ever tried the XML.au3 UDF of mLipok? yet? Wondering who uses AutoIT and what it can be used for? Link to comment Share on other sites More sharing options...
Sankesh Posted February 26, 2019 Author Share Posted February 26, 2019 11 minutes ago, LukeLe said: Hi @Sankesh, welcome to autoIT forum! Have you ever tried the XML.au3 UDF of mLipok? yet? Hi Luke, Googled the above XML.au3 file still not getting a clear idea on how to use it in my script..can i get sample script with the above cases involved. Thanks in advance! Link to comment Share on other sites More sharing options...
LukeLe Posted February 26, 2019 Share Posted February 26, 2019 @Sankesh 1. The UDF of mLipok is shipped with not only the UDF but also many examples, have you take a look at one of those yet? 2. You want to use it in your script, please let us know more clearly about HOW you want to use it in the script (store configs only, store data, write data to,etc) , or the XML file you want to read, etc? Wondering who uses AutoIT and what it can be used for? Link to comment Share on other sites More sharing options...
Sankesh Posted February 26, 2019 Author Share Posted February 26, 2019 Hi Luke, Sorry to disturb you..i downloaded the XMLWrapperEx_1.1.1.08 also xml_1.1.1.13 ..it is about making changes to the xml file as far as i understood. My requirement is i am trying to automate the installation of software using autoIT script with the below code.. #RequireAdmin Run(@ScriptDir & '\setup.exe') AutoItSetOption('MouseCoordMode',0) WinWait('Reena Desktop Server') WinActivate('Reena Desktop Server') MouseClick('primary', 444, 385, 1, 0) sleep(300) MouseClick('primary', 444, 385, 1, 0) sleep(300) MouseClick('primary', 444, 385, 1, 0) sleep(300) ControlClick ("Reena Desktop Server", "", "[CLASS:Button; INSTANCE:5]","left", 1, 0, 0) ;Required database selected sleep(300) MouseClick('primary', 444, 385, 1, 0) sleep(300) MouseClick('primary', 444, 385, 1, 0) sleep(300) Next step is, Windows GUI is asking for User id, Password, Data source where i have to feed it manually. Now i am trying to pick those values (User id, Password, Data source) saved in an xml file as below. <entry key="DBDefaultUserName">PIQ65</entry> <entry key="DBDefaultPassword">Passw8907</entry> Instead of feeding it manually, the script should fetch those values from xml and insert it in the windows GUI. Requesting for sample script of how data picked from xml and inserted in windows GUI. Appreciate your thoughts. Link to comment Share on other sites More sharing options...
LukeLe Posted March 1, 2019 Share Posted March 1, 2019 (edited) @Sankesh sorry I'm a little busy these days. In case the XML file is pretty complicated, please check the example XML__Examples_User__asdf1nit.au3 inside XML_1.1.1.13 folder. This shows you how to iterate through nodes, get values, etc. On 2/26/2019 at 6:11 PM, Sankesh said: Now i am trying to pick those values (User id, Password, Data source) saved in an xml file as below. <entry key="DBDefaultUserName">PIQ65</entry> <entry key="DBDefaultPassword">Passw8907</entry> If your XML file is short (just two lines like your post above) you can just process the string to extract the information you required. Please search for FileRead function in the help file. Once you got the data. Just fill the information into the GUI using Send or ControlSend function. Edited March 1, 2019 by LukeLe add more details about xml data Wondering who uses AutoIT and what it can be used for? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 1, 2019 Moderators Share Posted March 1, 2019 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Sankesh Posted March 4, 2019 Author Share Posted March 4, 2019 Hi Luke, Tried the same as you told before, am able to extract attribute from xml using FileRead(). I stored the output in two variables Result and Result1. Nex i want to run the script setup.exe but script is not moving to the next line of running the setup.exe file instead it is getting paused at the Msgbox line. Below is my code..please correct what i am missing it...CODE is executed only till Msgbox. #include <Process.au3> #include <Constants.au3> #include <String.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #RequireAdmin Local Const $sFile ="C:\Users\dnataraj\Desktop\sample.xml" $sLine=FileRead($sFile) $sSearch=_StringBetween($sLine,"<DBDefaultUserName>","</DBDefaultUserName>") $sSearch1=_StringBetween($sLine,"<DBDefaultPassword>","</DBDefaultPassword>") $sResult=_ArrayToString($sSearch,"") $sResult1=_ArrayToString($sSearch1,"") ;MsgBox(0,"",$sResult) ;MsgBox(0,"",$sResult1) Run(@ScriptDir & '\setup.exe') AutoItSetOption('MouseCoordMode',0) WinWait ('Reena Desktop Client') WinActivate('Reena Desktop Client') sleep(400) Send("{Enter}") MouseClick('primary', 172, 178, 1, 0) Opt('SendKeyDelay', 50) Send("$Result") Send ("{TAB}") Send ("$Result1") Send ("{TAB}") Also i would like to use ControlSend() instead of Send(). Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 4, 2019 Share Posted March 4, 2019 (edited) @Sankesh MsgBox will pause the script until you press "Ok" or any other button on the MsgBox, or if you don't specify a timeout (see function reference in the Help file). Then, you have another function that will wait some time: WinWait. It will wait forever if you don't specify a timeout there too (same as above). Send("$Variable") is an incorrect syntax; use Send($Variable) if you want to send the value of the variable (instead of its name), or use a more reliable function like ControlSend (see function reference in the Help file), or any other Control* function. Edited March 4, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Sankesh Posted March 4, 2019 Author Share Posted March 4, 2019 Hi Francesco, Sorry to disturb you. But i tried giving sleep also clicking ok button of the Msgbox. Now i removed msgbox and my code is not iterating to the nxt line. Can you please correct me...Thanks in Advance) #include <Process.au3> #include <Constants.au3> #include <String.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #RequireAdmin Local Const $sFile ="C:\Users\dnataraj\Desktop\sample.xml" $sLine=FileRead($sFile) $sUsername=_StringBetween($sLine,"<DBDefaultUserName>","</DBDefaultUserName>") $sPassword=_StringBetween($sLine,"<DBDefaultPassword>","</DBDefaultPassword>") $sResult=_ArrayToString($sUsername,"") $sResult1=_ArrayToString($sPassword,"") sleep(1000) Run(@ScriptDir & '\setup.exe') AutoItSetOption('MouseCoordMode',0) WinWait ('Reena Desktop Client') sleep(500) WinActivate('Reena Desktop Client') sleep(500) Send("{Enter}") sleep(1000) Send("{Enter}") MouseClick('primary', 172, 178, 1, 0) Opt('SendKeyDelay', 100) ControlSend("Reena Desktop Client","",1165,$Result) Send ("{TAB}") Opt('SendKeyDelay', 100) ControlSend("Reena Desktop Client","",1150,$Result1) Send ("{TAB}") Opt('SendKeyDelay', 30) Send ("C:\Program Files\Socrates\Logs") sleep(3000) MouseClick('primary', 445, 391, 1, 0) Send("{Enter}") sleep(3000) winwait ('Reena Desktop Client','Reena Desktop Client has been successfully installed') WinActivate ('Reena Desktop Client') sleep(3000) MouseClick('primary', 445, 391, 1, 0) sleep(3000) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 4, 2019 Share Posted March 4, 2019 @Sankesh Is "setup.exe" ran? If so, the problem is probably on the line WinWait(), which pauses the script until that window doesn't exist. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Sankesh Posted March 4, 2019 Author Share Posted March 4, 2019 No setup .exe is not running Link to comment Share on other sites More sharing options...
Sankesh Posted March 4, 2019 Author Share Posted March 4, 2019 Hi Francesco, My script is working now. The reason is i have placed the setup file in some other location.Now i corrected it..everything is working fine. But when i run the file the speed of execution is getting changed everytime i run.I believe some changes needs to be done in the sleep() value. When i compile the script to .exe the behaviour of script is quite different ..on one time the software is getting installed properly.when i run the same exe file again aftr 5 mins the behaviour is different..I am new to this tool yet i am able to pick it up the basic things..How to have the script control? Thanks &Regards, Sankesh Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 4, 2019 Share Posted March 4, 2019 @Sankesh As I've suggested above, you should use Win* and Control* functions to automate your application installation. In this way, you don't have to use Sleep function Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Sankesh Posted March 4, 2019 Author Share Posted March 4, 2019 @Francesco, need a help with the xml code..i am able to fetch data from normal xml file using _stringbetween function. But for the below its a properties.xml file where its has all data inside key values. Couldn't find any examples related to below xml structure. Can you help me with autoIT code to fetch DBDefaultUserName and DBDefaultPassword and to store it in a variable.i tried the below code but no luck. This is blocking me in getting my automation successful XML: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="DBDefaultUserName">PIQ72</entry> <entry key="DBDefaultPassword">PIQ72yut</entry> AutoIT code: Local Const $sFile ="C:\Users\dnataraj\Desktop\sqlproperties.xml" $file=FileRead($sFile) MsgBox(0, 'DONE!!!', XMLget($file, 'properties\entry\DBDefaultusername')) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 4, 2019 Share Posted March 4, 2019 @Sankesh Using SRE in this way, you'll obtain both Username and Password Spoiler #include <StringConstants.au3> Global $strFileContent = '<?xml version="1.0" encoding="UTF-8"?>"' & @CRLF & _ '<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">' & @CRLF & _ '<properties>' & @CRLF & _ '' & @CRLF & _ '<entry key="DBDefaultUserName">PIQ72</entry>' & @CRLF & _ '<entry key="DBDefaultPassword">PIQ72yut</entry>"' $arrResult = StringRegExp($strFileContent, '<entry key="(DBDefault(?:UserName|Password))">([^<]*)</entry>', $STR_REGEXPARRAYGLOBALMATCH) If UBound($arrResult) = 4 Then For $i = 0 To UBound($arrResult) - 1 Step 2 If $i < UBound($arrResult) - 1 Then ConsoleWrite($arrResult[$i] & " = " & $arrResult[$i + 1] & @CRLF) Next EndIf Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Sankesh Posted March 5, 2019 Author Share Posted March 5, 2019 #include <StringConstants.au3> Global $strFileContent = '<?xml version="1.0" encoding="UTF-8"?>"' & @CRLF & _ '<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">' & @CRLF & _ '<properties>' & @CRLF & _ '' & @CRLF & _ '<entry key="DBDefaultUserName">PIQ72</entry>' & @CRLF & _ '<entry key="DBDefaultPassword">PIQ72yut</entry>"' $arrResult = StringRegExp($strFileContent, '<entry key="(DBDefault(?:UserName|Password))">([^<]*)</entry>', $STR_REGEXPARRAYGLOBALMATCH) If UBound($arrResult) = 4 Then For $i = 0 To UBound($arrResult) - 1 Step 2 If $i < UBound($arrResult) - 1 Then ConsoleWrite($arrResult[$i] & " = " & $arrResult[$i + 1] & @CRLF) Next EndIf Hi Francesco, on running the above code i am getting error " Missing separator character after keyword.: ". Found ENDif missing for one of the if loop, still the same error. Checked the AutoIT forum and found $will be missing for a variable. As far as i understood in the above code..found xml tags are feeded inside the strFileContent. Instead i want to pass the xml path. Can i pass the xml path like this ? Global $strFileContent="C:\Users\dnataraj\Desktop\sam1.xml" Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 5, 2019 Share Posted March 5, 2019 @Sankesh The above code works fine. The "one line If" can be used when you have just an instruction to run, so it is used. 1 hour ago, Sankesh said: As far as i understood in the above code..found xml tags are feeded inside the strFileContent. Instead i want to pass the xml path. From your previous request: 19 hours ago, Sankesh said: Can you help me with autoIT code to fetch DBDefaultUserName and DBDefaultPassword and to store it in a variable. That's what the above code does. The variable $strFileContent is a fictitious variable to emulate the content of the XML file that you read with FileRead (here). So, if you want to pass the content of the XML file to a variable, then you should define the XML file path in a variable, and then create another one in which you read the content of the XML file. Something like this: ; XML File Path and Name Global $strXMLFileName = "C:\...XMLFile.xml" ; Read the content of the XML file Global $strFileContent = FileRead($strXMLFileName) ; Do something with the file content... Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Sankesh Posted March 6, 2019 Author Share Posted March 6, 2019 Still getting the error "Missing separator character after keyword.: ".Couldn't figure out what i am missing to fix the error. #include <StringConstants.au3> Global $strXMLFileName = "C:\sam1.xml" Global $strFileContent = FileRead($strXMLFileName) $arrResult = StringRegExp($strFileContent, '<entry key="(DBDefault(?:UserName|Password))">([^<]*)</entry>', $STR_REGEXPARRAYGLOBALMATCH) If UBound($arrResult) = 4 Then For $i = 0 To UBound($arrResult) - 1 Step 2 If $i < UBound($arrResult) - 1 Then ConsoleWrite($arrResult[$i] & " = " & $arrResult[$i + 1] & @CRLF) Next EndIf OUTPUT: "C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\dnataraj\Documents\AutoIt\server\TDT_Server.au3" C:\Users\dnataraj\Documents\AutoIt\server\TDT_Server.au3 (19) : ==> Missing separator character after keyword.: EndIf? EndIf^ ERROR >Exit code: 1 Time: 0.4151 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 6, 2019 Share Posted March 6, 2019 @Sankesh If you copy-paste the code in Notepad++, and set the property "Show all characters", you can see if there's an extra charatcer after the EndIf statement. In that case, just delete that line of your script, and re-type the EndIf instruction. By the way, use the one-line if, or add a EndIf statement after the UBound() If Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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