Jump to content
Sign in to follow this  
GaryM

New to AutoIt

Recommended Posts

GaryM

Hi,

I'm new to AutoIt and I'm trying to create a simple script that will open a IE window, change the address and enter a user name and password. This is just a test script for my own education. In the long run I want to do something similar but wait for the user to enter the user name and password before continuing on.

The window opens but the address text box doesn't chnage. It also doesn't end up with the focus. Do I need to pause to make sure the windows is fully open? I have listed the script here. Thanks for the help!!

; Script Start - Add your code below here

Dim $Title1

RunWait("C:\Program Files\Internet Explorer\iexplore.exe","",@SW_MAXIMIZE)

$Title1 = WinGetTitle("[active]")

;MsgBox(0, "Window Title", $Title1)

WinActivate($Title1)

ControlFocus($Title1, "", "ToolbarWindow322")

ControlSetText($Title1, "", "ToolbarWindow322", "https://email.secureserver.net/login.php")

;MsgBox(0, "Test Message", "Script Complete")

Gary

Share this post


Link to post
Share on other sites
Exit

#include <ie.au3>
$oIE = _iecreate("https://email.secureserver.net/login.php")
$oObject = _IEGetObjByName($oIE,"username")
        _IEPropertySet($oObject, "innertext", "MyUsername")
$oObject = _IEGetObjByName($oIE,"password")
        _IEPropertySet($oObject, "innertext", "MyPassword")

Edited by forumer100

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
flet

Hi Gary

IE.au3 in your include folder is perfect for this. Read the help file: it's very educational. The functions you are looking for all start with _IE..

To get you started (I have not tested the code):

#include <IE.au3>

; Create a browser window
$oIE = _IECreate ("yoururlhere")

; get pointers to the login form and username, password and signin fields
$o_form = _IEFormGetObjByName($oIE, "formname") ; you can find the form name in the page source
$o_login = _IEFormElementGetObjByName($o_form, "login") ; you can find the name of the input in the page source
$o_password = _IEFormElementGetObjByName($o_form, "password")
$o_signin = _IEFormElementGetObjByName($o_form, "submitbuttonname") ; you can find the name or id of the button in the page source

$username = "your username here"
$password = "your password here"

; Set field values and submit the form
_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)
_IEAction ($o_signin, "click")

Share this post


Link to post
Share on other sites
GaryM

Thank you for the quick reply! I'll check this out and test it. I know the _IE functions don't apply but would the same type of techniques work for Citrix?

Thansk again.,

Gary

Share this post


Link to post
Share on other sites
Exit

This site is not AutoIt friendly in IE9 browsermode. Submit and click fails. See

Therefore I included my _SetIE8() function.

Here is the modified code:

#include <ie.au3>
_IEErrorHandlerRegister()
_IEErrorNotify(1)
;#include '_setie8.au3'  ; added below

$oIE = _IECreate("https://email.secureserver.net/login.php")
_setie8($oIE) ; switch to IE8 browsermode
_IEAction($oIE, "refresh")
$oObject = _IEGetObjByName($oIE, "username")
_IEPropertySet($oObject, "innertext", "MyUsername")
$oObject = _IEGetObjByName($oIE, "password")
_IEPropertySet($oObject, "innertext", "MyPassword")
$oObject = _IEGetObjByName($oIE, "login_form")
_IEFormSubmit($oObject)

Exit

Func _SetIE8($_oIE) ; set Browsermode to IE8 since AutoIt has problems with submit in IE9
    If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IEDevTools", "Pinned") Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IEDevTools", "Pinned", "REG_DWORD", 0)
    $hwnd1 = _IEPropertyGet($_oIE, "hwnd")
    $titleOld = _IEPropertyGet($_oIE, "title")
    $titleNew = $titleOld & " " & Random(10000000, 99999999, 1)
    _IEPropertySet($_oIE, "title", $titleNew)
    ControlSend($hwnd1, "", "Internet Explorer_Server1", "{F12}")
    $titleF12 = $titleNew & " - F12"
    WinWait($titleF12, "", 60)
    WinSetState($titleF12, "", @SW_HIDE)
    $hwndF12 = WinGetHandle($titleF12)
    ControlSend($hwndF12, "", "ToolbarWindow321", "{alt}b8")
    Sleep(1000)
    WinClose($hwndF12)
    _IEPropertySet($_oIE, "title", $titleOld)
    WinActivate($hwnd1)
EndFunc   ;==>_SetIE8

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
GaryM

Thanks for the update. It worked for me after I changed the username field to loginlist. This is because I have multiple emails that I can signon to. Do you know of any limitations to using AutoIt with Citrix? Thanks again for the help!

Gary

This site is not AutoIt friendly in IE9 browsermode. Submit and click fails. See

Therefore I included my _SetIE8() function.

Here is the modified code:

#include <ie.au3>
_IEErrorHandlerRegister()
_IEErrorNotify(1)
;#include '_setie8.au3'  ; added below

$oIE = _IECreate("https://email.secureserver.net/login.php")
_setie8($oIE) ; switch to IE8 browsermode
_IEAction($oIE, "refresh")
$oObject = _IEGetObjByName($oIE, "username")
_IEPropertySet($oObject, "innertext", "MyUsername")
$oObject = _IEGetObjByName($oIE, "password")
_IEPropertySet($oObject, "innertext", "MyPassword")
$oObject = _IEGetObjByName($oIE, "login_form")
_IEFormSubmit($oObject)

Exit

Func _SetIE8($_oIE) ; set Browsermode to IE8 since AutoIt has problems with submit in IE9
    If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IEDevTools", "Pinned") Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IEDevTools", "Pinned", "REG_DWORD", 0)
    $hwnd1 = _IEPropertyGet($_oIE, "hwnd")
    $titleOld = _IEPropertyGet($_oIE, "title")
    $titleNew = $titleOld & " " & Random(10000000, 99999999, 1)
    _IEPropertySet($_oIE, "title", $titleNew)
    ControlSend($hwnd1, "", "Internet Explorer_Server1", "{F12}")
    $titleF12 = $titleNew & " - F12"
    WinWait($titleF12, "", 60)
    WinSetState($titleF12, "", @SW_HIDE)
    $hwndF12 = WinGetHandle($titleF12)
    ControlSend($hwndF12, "", "ToolbarWindow321", "{alt}b8")
    Sleep(1000)
    WinClose($hwndF12)
    _IEPropertySet($_oIE, "title", $titleOld)
    WinActivate($hwnd1)
EndFunc   ;==>_SetIE8

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.