Jump to content

How to pass parameters from xml to auto it script? - (Moved)


Sankesh
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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

@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 by LukeLe
add more details about xml data
Link to comment
Share on other sites

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

@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 by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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

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

@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

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

 

Link to comment
Share on other sites

#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

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

 

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...