Jump to content

Passing parameters using Send() from File


Iraj
 Share

Go to solution Solved by SOLVE-SMART,

Recommended Posts

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
Link to comment
Share on other sites

  • Iraj changed the title to Passing parameters using Send() from File

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

Link to comment
Share on other sites

1 hour ago, 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}"

 

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

Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

13 minutes ago, 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.

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! :)

Link to comment
Share on other sites

1 hour ago, ioa747 said:

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

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

Link to comment
Share on other sites

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

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Moderators

SOLVE-SMART,

Quote

How long should we wait

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

2 hours ago, Melba23 said:

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

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

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Solution

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

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

On 1/8/2023 at 7:53 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

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...

Link to comment
Share on other sites

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

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

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.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

13 hours ago, 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

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
Link to comment
Share on other sites

10 hours ago, 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 :)

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

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

×
×
  • Create New...