Jump to content

Auto Login to a website using Internet Explorer

Recommended Posts

Hello All,

I am new to auto It  and coding. Have only tried few automated logging for different websites.  The login pages of the websites which I have worked on were having form name with input type as text and it seems straight forward to automate their login using "_IEFormElementSetValue".

I have got a url, it does not have any form in the source page. On further analyzing I found that It does call some login page separately as below.

function showLogin(arg) {
  Global.pollingDialogDoc = null;
  var fresh = jQuery.isValidString(arg) && "fresh" == arg ? !0 : !1, appFrame = $("#appFrame");
  if ($("#modalFrame").show(), $("iframe").hide(), fresh || !appFrame.attr('src').match("html/login.html")) appFrame.attr('src', baseURL + 'html/login.html'), 
  appFrame.on('load', function() {
    setTimeout(function() {
      $("#modalFrame").hide(), appFrame.show();
    }, 1);
  }); else try {
  } catch (e) {}

I can simply use "send" and "mouse click" Method to automate the login but that doesn't seems very reliable. Is there any separate way to fill the user ID and password to the respective fields by having reference by frames or something. 

Appreciate if any one can point me to correct document or help in any way...!

Edited by singh54
Link to post
Share on other sites
  • 2 weeks later...

Hello ,

Appreciate your response, I have another website which does use JSP in background. Following is the source code for the same. Can any one help me in pointing to the correct direction for automating the login for this website. 

<!doctype html><html class="no-js" ng-app="rainierApp"><head><meta charset="utf-8"><title>{{ 'brand-company' | translate }} {{ 'brand-rainier' | translate }}</title><link rel="icon" href="favicon.ico?v=1"><meta name="description" content="{{ 'brand-company' | translate }} {{ 'brand-rainier' | translate }}"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><!-- Place favicon.ico and apple-touch-icon.png in the root directory --><link rel="stylesheet" href="styles/vendor.23c8625b.css"/><link rel="stylesheet" href="styles/main.b362bd11.css"/></head><body><!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
    your browser</a> to improve your experience.</p>
<![endif]--><!--Application stage--><div ng-view=""></div><!--[if lt IE 9]>
<script src="scripts/oldieshim.13b0bde1.js"></script>
<![endif]--><script src="scripts/vendor.a2691c43.js"></script><script src="scripts/scripts.1794f2ab.js"></script></body></html>



Link to post
Share on other sites
  • 5 weeks later...

Hello Danp2,

The URL won't be accessible. I have used inspect in google chrome and was able to get the below code for the login page.

<form ng-submit="model.submitAction()" class="ng-pristine ng-valid">

<div class="ds-login-text-inputs"><div class="ds-label-input-container"><label class="ds-label ng-binding">Username</label><input ng-model="model.username" class="ds-text-input ng-pristine ng-untouched ng-valid ng-empty" placeholder="Enter text" type="text" autofocus=""></div>

<div class="ds-label-input-container"><label class="ds-label ng-binding">Password</label><input ng-model="model.password" class="ds-text-input ng-pristine ng-untouched ng-valid ng-empty" placeholder="Enter text" type="password"></div></div>

<div class="ds-login-submit-buttons"><div class="ds-login-remember-me"><!-- No remember me checkbox --></div><button ng-disabled="isEmptyInput(model.username) || isEmptyInput(model.password)" class="ds-button-primary ng-binding" type="submit" role="button" disabled="disabled">Log in</button></div>



I am successfully able to put the credentials in the username and password field but the login button won't get enabled unless there is no keyboard simulation in both the fields. Not sure how to proceed further, please find my code below.

#include <IE.au3>

Local $oIE = _IECreate("https://serverhost/" )
Local $oForm = _IEFormGetCollection($oIE, 0)

Local $oQuery = _IEFormElementGetCollection($oForm, 0)
Local $oQuery1 = _IEFormElementGetCollection($oForm, 1)

_IEFormElementSetValue($oQuery, "username")  ; puts value to username
_IEFormElementSetValue($oQuery1, "VerySecuredpassword") ; Puts values to password

Appreciate your help on the same. 

Edited by singh54
Link to post
Share on other sites


Thank you very much for the help, I am looking into it but was just wondering if there is any other way by which I can achieve this ?

I am trying the following code .

Local $oIE = _IECreate("URL" )
Local $hWnd = _IEPropertyGet($oIE, "hwnd")

Local $oForm = _IEFormGetCollection($oIE, 0)

Local $oQuery = _IEFormElementGetCollection($oForm, 0)
Local $oQuery1 = _IEFormElementGetCollection($oForm, 1)

_IEAction($oQuery, "focus")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "username") ; It is working fine.
_IEFormElementSetValue($oQuery1, "Verystrongpassword")

_IEAction($oQuery1, "focus")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{space} {BS}") ; to stimulate the keypad action but it is not working as expected :(

Send ("{ENTER}")

It actually opens in private Internet explorer, not sure how and behaves strangely, sometimes the password is not completely sent.

Link to post
Share on other sites
  • 2 weeks later...

Hello Danp2,

Hope you are doing good..! I  have tried  many different codes found in this forum and at last the following code runs fine and was able to login.

1 Out of 5 times I have seen that the url throw an "invalid user and password error", I am not sure on the root cause yet. I wanted to know your thoughts on the same.

#include <IE.au3>

Local $oIE = _IECreate("URL" )

Local $oForm = _IEFormGetCollection($oIE, 0)

Local $oQuery = _IEFormElementGetCollection($oForm, 0)
Local $oQuery1 = _IEFormElementGetCollection($oForm, 1)
Local $oQuery2 = _IEFormElementGetCollection($oForm, 2)

_IEAction($oQuery, "focus")
_IEFormElementSetValue($oQuery, "username")
Local $oEvt = $oIE.document.createEvent("HTMLEvents")
$oEvt.initEvent("change", True, False)

_IEAction($oQuery1, "focus")
_IEFormElementSetValue($oQuery1, "VeryStrongPassword")
Local $oEvt = $oIE.document.createEvent("HTMLEvents")
$oEvt.initEvent("change", True, False)

; The change event above was able to enable the submit button and I am using IEAction to simulate click.

_IEAction($oQuery2, "focus")
_IEAction($oQuery2, "Click")

In addition to that, I want to learn more on events available in autoit. I would really appreciate if you can point me to any available URL where I can learn this in detail.

Edited by singh54
Link to post
Share on other sites
6 minutes ago, singh54 said:

Out of 5 times I have seen that the url throw an "invalid user and password error", I don't see any issue with my code. Could you please help if there is anything I can do to avoid this error.

There's no error checking in your code, so that would be a good place to start.

7 minutes ago, singh54 said:

While working on this, I got curious to learn more on events available in auto it. I would really appreciate if you can point me to any available URL where I can learn this in detail.

Not curious enough to use Google? 🙄

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By HoangDung
      This is the function that returns the result from cmd, initially i connect to the network wait then i make a call to the above _GetDOSOutput($sCommand) function i want to wait 1 period of time netsh wlan connect name="name" actually but after starting to execute the netsh wlan show interfaces command i tried adding a timeout command it seems to have ignored the timeout command?
      #include <WindowsConstants.au3> #include <Constants.au3> Func _GetDOSOutput($sCommand) Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = '' Local $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $sOutput &= StdoutRead($iPID, False, False) If @error Then ExitLoop EndIf Sleep(10) WEnd Return $sOutput EndFunc Local $sCommand= 'netsh wlan delete profile name="wait" & netsh wlan connect name="name" interface="Wi-fi" & netsh wlan show interfaces' MsgBox(0,0,_GetDOSOutput($sCommand))  
    • By jiaojiaodubai
      I am happy to see that the latest version of AutoIt3 can already be searched, downloaded and installed in the Windows 10+built-in package manager (Winget). Therefore, we can automatically install AutoIt3 itself by writing Powershell scripts, which helps to quickly deploy the working environment of AutoIt3 on new machines.

      Now, although AutoIt3 can be found and installed in Winget, its dedicated editor, SciTE4AutoIt, does not support this. I submitted a package request for SciTE4AutoIt to the Winget development team on GitHub and provided a download link. Then its developer replied to me:
      In other words, Winget developers believe that our website prevents Winget from directly downloading the .exe file of SciTE4AutoIt.

      In fact, I don't know much about the technical details he said, but I think we can make some changes to make SciTE4AutoIt more accessible.
    • By D3fr0s7
      I'm trying to make one tray item delete another, but when I do this, all tray items that were created after the deleted item don't work as intended, as if their controlID's were all shifted down one value, and their corresponding tray items now (after deletion) run the code of the tray item before it. Am I missing something? Is there a better way to accomplish what I'm trying to do?
      #include <TrayConstants.au3> #include <Array.au3> HotKeySet ( "{ESC}", "Abort" ) Opt ( "TrayMenuMode", 3 ) TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. Global $aTray[8] ; Defines array to hold tray items. $aTray[0] = TrayCreateItem ( "Test 1 (Name Test 5)" ) $aTray[1] = TrayCreateItem ( "Test 2 (Delete Test 5)" ) $aTray[2] = TrayCreateItem ( "Test 3 (Restore Test 5)" ) $aTray[3] = TrayCreateItem ( "Test 4 (Check if Test 5 is blank or space)" ) $aTray[4] = TrayCreateItem ( "Test 5 Delete Me" ) $aTray[5] = TrayCreateItem ( "Test 6 (Check Test 5 Text)" ) $aTray[6] = TrayCreateItem ( "Test 7 (Read Values)" ) $aTray[7] = TrayCreateItem ( "Test 8 (Count Blanks)" ) While 1 Switch TrayGetMsg() Case $aTray[0] ; "Test 1" Change Test 5 Text. If TrayItemGetText ( $aTray[0] ) <> "" Then Global $TrayText = InputBox ( "Test", "Choose text for Test 5", "Test 5 Delete Me" ) TrayItemSetText ( $aTray[4], $TrayText) EndIf Case $aTray[1] ; "Test 2" Deletes "Test 5". If TrayItemGetText ( $aTray[1] ) <> "" Then Global $TrayDeletedName = TrayItemGetText ( $aTray[4] ) TrayItemDelete ( $aTray[4] ) _ArrayInsert ( $aTray, 4 ) EndIf Case $aTray[2] ; "Test 3" Restores "Test 5". If TrayItemGetText ( $aTray[2] ) <> "" Then $aTray[4] = TrayCreateItem ( $TrayDeletedName ) EndIf Case $aTray[3] ; "Test 4" Check if Test 5 value is blank, space, or filled. If TrayItemGetText ( $aTray[3] ) <> "" Then If TrayItemGetText ( $aTray[4] ) = "" Then MsgBox ( 0, "Test", "Test 5 is blank" ) ElseIf TrayItemGetText ( $aTray[4] ) = " " Then MsgBox ( 0, "Test", "Test 5 is not blank (space)" ) Else MsgBox ( 0, "Test", "Test 5 is assigned a value" ) EndIf EndIf Case $aTray[4] ; "Test 5" (Item to test for, during, and after deletion). If TrayItemGetText ( $aTray[4] ) <> "" Then MsgBox ( 0, "Test", "I'm here!" ) EndIf Case $aTray[5] ; "Test 6" Displays Text from Test 5 item. If TrayItemGetText ( $aTray[5] ) <> "" Then $Test5Text = TrayItemGetText ( $aTray[4] ) MsgBox ( 0, "Test", "Test 5 Text: " & $Test5Text ) EndIf Case $aTray[6] ; "Test 7" Displays all item values. If TrayItemGetText ( $aTray[6] ) <> "" Then MsgBox ( 0, "Test", "$aTray[0]: " & $aTray[0] & @CRLF & _ "$aTray[1]: " & $aTray[1] & @CRLF & _ "$aTray[2]: " & $aTray[2] & @CRLF & _ "$aTray[3]: " & $aTray[3] & @CRLF & _ "$aTray[4]: " & $aTray[4] & @CRLF & _ "$aTray[5]: " & $aTray[5] & @CRLF & _ "$aTray[6]: " & $aTray[6] & @CRLF & _ "$aTray[7]: " & $aTray[7] & @CRLF ) EndIf Case $aTray[7] ; "Test 8" Counts all blanks in tray values. If TrayItemGetText ( $aTray[7] ) <> "" Then Global $blankCount = _ArrayFindAll ( $aTray, "" ) If $blankCount = -1 Then If @error = 6 Then MsgBox ( 0, "Test", "Error, No blanks present") EndIf Else MsgBox ( 0, "Test", "# of blanks: " & $blankCount ) EndIf EndIf EndSwitch WEnd Func Abort() Exit EndFunc Here is a test script I created to try to troubleshoot the problem on my own, with no luck. pay specific attention to "Test 2" ($aTray[1]), "Test 5" ($aTray[4]), and how every tray item after "Test 5" ($aTray[4]) behaves after deletion. Clicking "Test 2" will delete tray item "Test 5", after deletion every item runs the code of the tray item that was established before it (ex. "Test 3" and "Test 4" run their respective code, "Test 5" no longer exists, "Test 6" runs "Test 7", "Test 7" runs "Test 8"), and the last item ("Test 8" $aTray[7]) has no effect when the tray item is clicked. 

      I understand that deleting the tray item changes the controlID, but I don't know in what way it does, and therefore how I can fix it to be able to achieve what I want it to. I appreciate any help or guidance with this problem.

      To clarify, what I'm ultimately trying to do is create a 'while' loop with switch case functions that can exist without necessarily being linked to a tray item, so that I can add and delete them at liberty using the script's functions, without having to differentiate switch case functions with if functions (if $aTray[x] exists, then use this set of switch case functions, etc.). 

      Please, I am in pain. Water come school me again pls
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.26 contains 214 functions divided into these topics:
      window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) GUI numberbox controls for integer, real, binary and hexadecimal input logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By Zaoka
      for couple of years I'm using  Jos script for sending reports, email with excel attachment. But from last week i'm getting this error when sending excel or word attachment
      message has lines too long for transport jpeg, pdf works with no problems, any sugestion ?
  • Create New...