Jump to content

Passing parameters using Send() from File


Go to solution Solved by SOLVE-SMART,

Recommended Posts

Posted (edited)

Greetings!

I am trying to pass parameters using Send () function as below

$sFilePath = @ScriptDir & "\config.ini"
Local $hFileOpen = FileOpen($sFilePath, $FO_READ)
Local $sURLUsername = FileReadLine($hFileOpen, 1)
Local $sURLPassword = FileReadLine($hFileOpen, 2)
Local $sAutomation = FileReadLine($hFileOpen, 3)

Run("chrome facebook.com")
Sleep(5000)
Send($sAutomation)

FileClose($hFileOpen)

The config.ini file contains below lines

abcd
wxyz
$sURLUsername{TAB}$sURLPassword{ENTER}

While running,  I am getting $sURLUsername & $sURLPassword in the username & password field instead of abcd & wxyz as provided.

Refer image below:

image.thumb.png.db254a33072bd0a597c8a5457c097458.png

 

Where am I going wrong? Any suggestions or assistance will be grateful. 

Edited by Iraj
other
  • Iraj changed the title to Passing parameters using Send() from File
Posted (edited)

try this maybe  help 

$sAutomation = "^aabcd{TAB}wxyz{ENTER}"
ShellExecute("https://www.facebook.com/login.php/")
WinWait("Log into Facebook — ")
Send($sAutomation)

in ini file need only one line. The send line like $sAutomation

otherwise

$sAutomation = "^a" & $sURLUsername & "{TAB}" & $sURLPassword & "{ENTER}"

 

Edited by ioa747

I know that I know nothing

Posted
  On 1/7/2023 at 9:03 AM, ioa747 said:

try this maybe  help 

$sAutomation = "^aabcd{TAB}wxyz{ENTER}"
ShellExecute("https://www.facebook.com/login.php/")
WinWait("Log into Facebook — ")
Send($sAutomation)

in ini file need only one line. The send line like $sAutomation

otherwise

$sAutomation = "^a" & $sURLUsername & "{TAB}" & $sURLPassword & "{ENTER}"

 

Expand  

That I tried, the issue is the username & password will be changing often & I require it as mentioned above (in .ini file) & also will be confusing for the people who will use it.

I just need to figure it out where I am going wrong. Thanks anyways! If any other way, do lemme know

  • Moderators
Posted

Iraj,

Before we go any further, how about explaining why you have the need to read usernames and passwords from a file in order to login. This implies that you will be logging into several accounts rather then just your own. So just what is going on?

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 1/7/2023 at 3:29 PM, Melba23 said:

Iraj,

Before we go any further, how about explaining why you have the need to read usernames and passwords from a file in order to login. This implies that you will be logging into several accounts rather then just your own. So just what is going on?

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Expand  

I am currently working on website automation project for an organisation for SSO module which includes url single sign on.

Thats the only case, nothing else! :)

Posted
  On 1/7/2023 at 1:46 PM, ioa747 said:

$sURLUsername & "{TAB}" & $sURLPassword & "{ENTER}"  instead of  $sURLUsername{TAB}$sURLPassword{ENTER}

Expand  

Tab & Enter are happening. Just that the actual username & password are not passing.

Posted

Hi @Melba23,

is the legality of the thread proofed or not? How long should we wait until we could post suggestions to the user?
No pressure, I just don't know how to handle this 😅 .

Best regards
Sven

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
  • Moderators
Posted

SOLVE-SMART,

  Quote

How long should we wait

Expand  

As long as it takes - some of us do have a life away from the forum!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

Iraj,

Happy to accept that explanation. The thread is again open to suggestions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)
  On 1/8/2023 at 11:33 AM, Melba23 said:

[...] As long as it takes - some of us do have a life away from the forum! [...]

Expand  

I didn't want to stress you out @Melba23 😔 , it was really just a question of how to behave, not more.
Anyway, understood 👍 . Next time I am aware of how to.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
  • Solution
Posted (edited)

Hi @Iraj,

this code would run properly:

Opt('MustDeclareVars', 1)
Opt('SendKeyDelay', 40)

_Login()

Func _Login()
    Local Const $sFilePath    = @ScriptDir & '\config.ini'

    Local Const $hFileOpen    = FileOpen($sFilePath)
    Local Const $sURLUsername = FileReadLine($hFileOpen, 1)
    Local Const $sURLPassword = FileReadLine($hFileOpen, 2)
    Local Const $sAutomation  = FileReadLine($hFileOpen, 3)

    FileClose($hFileOpen)

    ShellExecute('https://www.facebook.com/login.php/')
    Sleep(3000)

    Send(Execute($sAutomation))
EndFunc
  • You missed to Execute() the third read line as this is a string which has to be executed before Send().
    •   Line three in config.ini: $sURLUsername & '{TAB}' & $sURLPassword & '{ENTER}'
  • You also should use the suggested ShellExecute() of @ioa747.
  • The AutoIt option SendKeyDelay is for a bit of robustness. Between each keystroke, a short delay is proceeded before the next keystroke happen.

But let's be honest, if you really want to do website automation for a company in such a way, I believe this approach will lead to an quick end. You will struggle after the facebook login without using a more robust approach like WebDriver (au3WebDriver, Selenium, WebdriverIO, Nightwatch.js etc.).

What should be the next step @Iraj? Do you want to get more into WebDriver? Let us know, there is a great Wiki and much more which would help a lot, am I sure.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted
  On 1/8/2023 at 2:23 PM, SOLVE-SMART said:

Hi @Iraj,

this code would run properly:

Opt('MustDeclareVars', 1)
Opt('SendKeyDelay', 40)

_Login()

Func _Login()
    Local Const $sFilePath    = @ScriptDir & '\config.ini'

    Local Const $hFileOpen    = FileOpen($sFilePath)
    Local Const $sURLUsername = FileReadLine($hFileOpen, 1)
    Local Const $sURLPassword = FileReadLine($hFileOpen, 2)
    Local Const $sAutomation  = FileReadLine($hFileOpen, 3)

    FileClose($hFileOpen)

    ShellExecute('https://www.facebook.com/login.php/')
    Sleep(3000)

    Send(Execute($sAutomation))
EndFunc
  • You missed to Execute() the third read line as this is a string which has to be executed before Send().
    •   Line three in config.ini: $sURLUsername & '{TAB}' & $sURLPassword & '{ENTER}'
  • You also should use the suggested ShellExecute() of @ioa747.
  • The AutoIt option SendKeyDelay is for a bit of robustness. Between each keystroke, a short delay is proceeded before the next keystroke happen.

But let's be honest, if you really want to do website automation for a company in such a way, I believe this approach will lead to an quick end. You will struggle after the facebook login without using a more robust approach like WebDriver (au3WebDriver, Selenium, WebdriverIO, Nightwatch.js etc.).

What should be the next step @Iraj? Do you want to get more into WebDriver? Let us know, there is a great Wiki and much more which would help a lot, am I sure.

Best regards
Sven

Expand  

Its working ... Thanks

 

Regarding Webdriver, I was planning to integrate python for identifying the html elements more precisely & go on forward as I have worked on python before.

 

Any other idea will be appreciated...

Posted

Hi @Iraj,

good to read: it works 😀 .
Regarding Python and WebDriver => you will be focusing on Selenium then, am I right?

But I don't understand why you want to do things with AutoIt, like reading values from a file and do a website login, afterwards you will work with Python to do the rest?
Why not stay on Python or AutoIt for both tasks?

Depending on your experience with one of the languages, I recommend to stay on one of them for browser automation.
In case you plan to do more then browser stuff, it would be interesting what exactly to come to an conclusion which language fits the tasks better.

Best regards
Sven

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

  Reveal hidden contents
Posted

Since you're dealing with login information, you might consider using a password manager instead of storing the username/password in plain text in a file. I personally use KeePass with AutoIt and have a UDF that I put together to easily use it. See my signature for a link if you're interested :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents
Posted (edited)
  On 1/9/2023 at 3:52 PM, SOLVE-SMART said:

Hi @Iraj,

good to read: it works 😀 .
Regarding Python and WebDriver => you will be focusing on Selenium then, am I right?

But I don't understand why you want to do things with AutoIt, like reading values from a file and do a website login, afterwards you will work with Python to do the rest?
Why not stay on Python or AutoIt for both tasks?

Depending on your experience with one of the languages, I recommend to stay on one of them for browser automation.
In case you plan to do more then browser stuff, it would be interesting what exactly to come to an conclusion which language fits the tasks better.

Best regards
Sven

Expand  

My project head wanted python & one open source scripting lang for this. I’ll anyhow use python predominantly. Lets see. If I come to a better solution I’ll keep you updated

Edited by Iraj
Posted
  On 1/9/2023 at 6:47 PM, seadoggie01 said:

Since you're dealing with login information, you might consider using a password manager instead of storing the username/password in plain text in a file. I personally use KeePass with AutoIt and have a UDF that I put together to easily use it. See my signature for a link if you're interested :)

Expand  

Well I need to check. The issue is not all our clients use KeePass, and we are in similar domain, so ideally we can’t use it. Still I’ll check with my project head if we can integrate it

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
×
×
  • Create New...