Sign in to follow this  
Followers 0
TheMaestro

SAP Netweaver login

10 posts in this topic

Hello,

has anyone tried to automate login to SAP NetWeaver application? (login screen attached) I cannot figure it out (my knowledge of AutoIt is basic). I tried things like sendkey, but I was unable to write into the fileds (probably because of it's a Java Application). I appreciate any help you can provide. Thank you.

Cheers,

M.

post-80469-0-48127900-1370953042_thumb.p

Share this post


Link to post
Share on other sites



 

Here ya go

#include <IE.au3>

$Url = 'URL of Website'
$User = 'Username'
$Pwd = 'Password'

$test = _IEAutoLogin($Url, $User, $Pwd)

Func _IEAutoLogin($sUrl, $sUsername, $sPwd)
$oIE = _IECreate($sUrl)
_IEErrorNotify(False)
_IEErrorHandlerRegister()
$oForms = _IEFormGetCollection($oIE)
If @error Then
  Return SetError(1, _IEErrorHandlerDeRegister(), $oIE) ;'no forms --> no login'
Else
  $Index = 0
  For $oForm In $oForms
   $oFormElements = _IEFormElementGetCollection($oForm)
   If IsObj($oFormElements) Then
    $IndexElement = 0
    For $oElement In $oFormElements
     If $oElement.Type = 'password' Then
      $oPwd = _IEFormElementGetObjByName($oForm, $oElement.Name)
      _IEFormElementSetValue($oPwd, $sPwd)
      For $i = $IndexElement - 1 To 0 Step -1
       $oUser = _IEFormElementGetCollection($oForm, $i)
       If $oUser.Type = 'text' Then
        _IEFormElementSetValue($oUser, $sUsername)
        ExitLoop
       EndIf
      Next
      If $oForm.action <> "0" And Not StringInStr($oForm.action, '.php') Then  ;submit
       _IEFormSubmit($oForm, 0)
       _IELoadWait($oIE)
      Else  ;click
       For $i = $IndexElement + 1 To $IndexElement + 10 ;check the next 10 elements
        $oButton = _IEFormElementGetCollection($oForm, $i)
        If $oButton.Type = 'submit' Then
         _IEAction($oButton, "click")
         ExitLoop
        EndIf
       Next
      EndIf
      Return SetExtended(_IEErrorHandlerDeRegister(), $oIE)
     EndIf
     $IndexElement += 1
    Next
   EndIf
   $Index += 1
  Next
EndIf
Return SetError(2, _IEErrorHandlerDeRegister(), $oIE) ;no password-field found
EndFunc   ;==>_IEAutoLogin

Thank you very much for the reply. But when I run the script a I get this error:

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:...SAPlogon.au3"

C:\Program Files\AutoIt3\Include\IE.au3 (560) : ==> The requested action with this object has failed.:

WEnd

WEnd^ ERROR

>Exit code: 1    Time: 0.519

When I tried to build an exe file and run that I got error on 245th line of IE.au3. In this file, close to this line, there is an comment about some weird behaviour of IE9, which I am using. Could this be related? Thank you.

M.

Share this post


Link to post
Share on other sites

So are we done with this portion of the Forum Rules "Bypassing of security measures - log-in"?


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

So are we done with this portion of the Forum Rules "Bypassing of security measures - log-in"?

I am not bypassing anything, I have access to the server. I just want to automate login with valid credentials, because I need to check about 30 of these servers every day and take some screenshots for the report. So this would ease up the situation a lot....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

 

Have you saved it to your Desktop then tried running it? I just copied the code I gave you and it worked for me, are you sure you didn't edit anything in the code other than the following fields?

$Url = 'URL of Website'
$User = 'Username'
$Pwd = 'Password'

 

Yes of course, I saved it, changed only url, user, pwd and got the error. I've done it today again with the same result. It's weird. Maybe there is a difference in AutoIt version / IE.au3 file; or internet explorer version (like I wrote before). I have AutoIt v3 and IE9

Update:

I finally get the script to work with no errors (just added #RequireAdmin in the beginning of the script - no other change). but nothing happened, only the webpage was loaded... Have you tried this script with SAP Netweaver, or is this a generic login script you used on some webpages? I ask because SAP Netweaver is a java page, maybe this is the reason why the script isn't working...

Edited by TheMaestro

Share this post


Link to post
Share on other sites

Dont get me wrong, I am on your side in that automating valid credentials should be legit.  But a very different precedent has been set, and I am fan of (and probably dickfor) pointing out inconsistencies in the application of the ruleset.  A couple of examples:


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Hi,

I don't know if you have still the problem to connect to SAP netweaver but the following code is working for me.

;
; AutoIt Version: 3.0
; Language:       English
; Platform:       WinXP
; Author:         Paul Devadder
;
; Script Function:
;   Automatizing connection to EOP
;

#include <IE.au3>

$Url = 'URL of Website'
$User = 'Username'
$Pwd = 'Password'



; Create a browser window and navigate to hotmail
$oIE = _IECreate()
_IENavigate($oIE, $Url)

; get pointers to the login form and username and password fields
$o_form = _IEFormGetObjByName($oIE, "logonForm")
$o_login = _IEFormElementGetObjByName($o_form, "j_user")
$o_password = _IEFormElementGetObjByName($o_form, "j_password")

; Set field values and submit the form
_IEFormElementSetValue($o_login, $User,0)
_IEFormElementSetValue($o_password, $Pwd,0)
Local $hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($o_form, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

Exit

Regards, Paul

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  
Followers 0