Jump to content
singh54

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 {
    window.frames.appFrame.updatePageFromIndex();
  } 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

Share this post


Link to post
Share on other sites

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>

===================================================

Regards,
Shyam

Share this post


Link to post
Share on other sites

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>

</form>

-------------------------------------------------------------------------------------------------------------------------------------------------------

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

Share this post


Link to post
Share on other sites

Hi,

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")

Sleep(5000)
_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.

Share this post


Link to post
Share on other sites

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)
$oQuery.dispatchEvent($oEvt)

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

; 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

Share this post


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

Share this post


Link to post
Share on other sites

HI Danp2

Apologies, I might be asking for very trivial help as I am very new to programming, started 3 months back only :( .
Also, I tried from my end and still trying to find the details of events in AUTOIT. 

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
    • By Pured
      I am looking to create a script which refreshes/reads a webpage every few seconds. My goal is to see if the page has changed, then I will send myself a notification that the webpage has been updated.
       
      However, rather than downloading the entire webpage every single time, is there a way to check when the webpage last updated?
       
      If not, is there away to partially download/read html source until a specific tag is hit?
       
      Goal: I would like to increase my poll rate and not excessively waste data.
×
×
  • Create New...