Jump to content

[SOLVED] Web Login


Recommended Posts

Talk about scripting noobs, I am probably at the top.

I've been trying to automate a login to a certain site for a project I am working on. I've tried several scripts, and none seem to work. I've also been researching the forums with no luck.

I was able to create a script using mouseclick and send commands, however, this script will be shared among colleagues, and not all have the same size screen, therefore, a mouseclick at position 118 on one PC, is not the same on another (smaller/larger) monitor.

The site I am trying to get to is (https://.........) and for testing purposes, the username and password would be both "test". This site also has a drop down menu that I will need to choose (....) prior to clicking "Log In"

Any help would be greatly appreciated.

BTW, I have also tried using Debugbar, as I was trying to figure this out myself, but no luck.

Edited by Malpario
Link to comment
Share on other sites

You should check out the IE Functions in the Help File.

Thank you MrMitchell, I've been looking at the IE Functions in the Help file for the last two days (from _IE_Example to _IETagNameGetCollection), and no luck. I've also been searching the forums (AutoIt and Others) and testing different scripts and still no luck.
Link to comment
Share on other sites

The login buttons are in a FRAME called "launcher"

Once you've hooked to that frame, the input called "SaPrincipalName" needs to be your username.

"SaPrincipalPassword" is the password.

The drop down list is called "SaRepositoryName", select some value.

Then hit "submit".

Link to comment
Share on other sites

To get to the frame, use "_IEFrameGetObjByName"

To assign values to the boxes, use "_IEFormElementGetObjByName" to assign the Object targetted to a VARIABLE, then use "_IEFormElementSetValue" to assign a value to the OBJECT in the variable.

To set the value for the dropdown box, same thing.

The login buttons are in a FRAME called "launcher"

Once you've hooked to that frame, the input called "SaPrincipalName" needs to be your username.

"SaPrincipalPassword" is the password.

The drop down list is called "SaRepositoryName", select some value.

Then hit "submit".

Link to comment
Share on other sites

To get to the frame, use "_IEFrameGetObjByName"

To assign values to the boxes, use "_IEFormElementGetObjByName" to assign the Object targetted to a VARIABLE, then use "_IEFormElementSetValue" to assign a value to the OBJECT in the variable.

To set the value for the dropdown box, same thing.

Thank you PowerCat.

I will give the script a try and post what happens, along with the script for review.

Link to comment
Share on other sites

Thank you PowerCat.

I will give the script a try and post what happens, along with the script for review.

Here is what I have come up with so far, and still no luck. This is just to input the username and password. The dropdown and submit, is another animal.

Keep in mind, I am new to this:

#include <IE.au3>

Opt("WinTitleMatchMode", 2)

$oIE = _IECreate ("https://dssweb.cds-global.com/sagent/")

Sleep(2000)

$o_form = _IEFrameGetObjByName ($oIE, "launcher")

$o_login = _IEFormElementGetObjByName ($o_form, "SaPrincipalName")

$o_password =_IEFormElementGetObjByName ($o_form, "SaPrincipalPassword")

$username = "test"

$password = "test"

_IEFormElementSetValue ($o_login, $username)

_IEFormElementSetValue ($o_password, $password)

WinSetState ( "Internet", "", @SW_MAXIMIZE )

Link to comment
Share on other sites

This works:

#include <IE.au3>
Opt("WinTitleMatchMode", 2)
$oIE = _IECreate ("https://dssweb.cds-global.com/sagent/")
;~ Sleep(2000)

$o_form = _IEFrameGetObjByName ($oIE, "launcher")
;~ $o_login = _IEFormElementGetObjByName ($o_form, "SaPrincipalName")
$o_login = _IEGetObjById ($o_form, "SaPrincipalName")
;~ $o_password =_IEFormElementGetObjByName ($o_form, "SaPrincipalPassword")
$o_password = _IEGetObjById ($o_form, "SaPrincipalPassword")

$username = "test"
$password = "test"

_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)

WinSetState ( "Internet", "", @SW_MAXIMIZE )

And you don't need to Sleep(2000) because the _IECreate already waits for the page to completely load before continuing on with the script.

Edit/add: I know this is just a test script, but to avoid confusion you might want to change all $o_form references to $o_frame because it's actually a frame you're dealing with. :huh2:

Edited by MrMitchell
Link to comment
Share on other sites

Thank you very much. It works like a charm. I was even able to have it select from the drop down menu :huh2:.

All I need to figure out now is the last step of selecting the Log In button. I am sure a little google/AutoIt forum searching would help.

Thanks again.

Link to comment
Share on other sites

Thank you very much. It works like a charm. I was even able to have it select from the drop down menu :huh2:.

All I need to figure out now is the last step of selecting the Log In button. I am sure a little google/AutoIt forum searching would help.

Thanks again.

You can click the button a couple of different ways.

The easiest is using "_IEFormSubmit($oForm)" but I found that not to work in some cases

This next one will do a "Click" action on the object assigned to $oButton (in this case, the button has been assigned to that variable)

$oButton = _IEFormElementGetObjByName($oForm, "BUTTONNAME")
_IEAction($Button,"click")
Link to comment
Share on other sites

This should do it... this method enumerates all form elements of type "input" in the frame (I'm still using $o_form so that this works with your current code) then when the value of the input matches "Log In", exit the loop then "click" the last $oInput. This is just one way, there are a few more and even more but you would have to change more of your previous code.

$oInputs = _IETagNameGetCollection ($o_form, "input")       
For $oInput In $oInputs
    If $oInput.value = "Log In" Then
        ExitLoop
    EndIf
Next

_IEAction($oInput, "click")

Edit: Probably not the best idea to compare the string like that, so instead of:

"If $oInput.value = "Log In" Then", use:

If StringCompare($oInput.value, "Log In") = 0 Then

Edited by MrMitchell
Link to comment
Share on other sites

Truly amazing.

MrMitchell, Powercat and all, you guys are great.

Thank you for all the help. This is just one piece of the process, but for some reason, was proving to be the more difficult part.

Thanks again. I am sure I will have other questions, so, see you soon.

Link to comment
Share on other sites

Ok, Im back.

I am almost done with my script, thanks to you guys. All that is left is copying a column from an excel spreadsheet (account number), pasting the account number under the webform, submitting the account and looping back to paste the second account number (and so on) until the end of the file.

I've attached the script I have created so far, the issue I am having is towards the end "_IEFormElementSetValue ($o_Input2, "Damn")". Instead of "DAMN", I want it to paste the account number from the spreadsheet, and continue to the next account number, until it ends.

Any help would be great.

I've attached 2 files (the excel spreadsheet and the webpage)

#include <File.au3>
#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>

;-----------------------------------------------------------------------------
;Open Excel
;-----------------------------------------------------------------------------
local $oExcel = _ExcelBookOpen("C:\BBWK\export1SF.xls")
$aArray1 = _ExcelReadSheetToArray($oExcel,2,3,0,1,True)
_ExcelBookClose($oExcel)
$rows = UBound($aArray1)-1
_ArrayDisplay($aArray1)

Sleep (2000)
;-----------------------------------------------------------------------------
;Begin Loggin In to Sagent Website
;-----------------------------------------------------------------------------
Opt("WinTitleMatchMode", 2)
$oIE = _IECreate ("https://Some Site/")

$o_frame = _IEFrameGetObjByName ($oIE, "launcher")
$o_login = _IEGetObjById ($o_frame, "SaPrincipalName")
$o_password = _IEGetObjById ($o_frame, "SaPrincipalPassword")
$o_Input = _IEGetObjById($o_Frame, "SaRepositoryName")

$username = "test"
$password = "test"

_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)
_IEFormElementOptionselect ($o_Input, "SARPSERV" , 1, "byText")

$oInputs = _IETagNameGetCollection ($o_Frame, "input")       
For $oInput In $oInputs
    If $oInput.value = "Log In" Then
        ExitLoop
    EndIf
Next
_IEAction($oInput, "click")
;-----------------------------------------------------------------------------
;Click on Update Customer Link and choose Handle
;-----------------------------------------------------------------------------

Sleep (3000)
_IELinkClickByIndex ($o_frame, 0)
Sleep (5000) ;Allows time to load the page  

$o_frame = _IEFrameGetObjByName ($oIE, "launcher")
$oFrameB = _IEFrameGetObjByName($oIE, "target" )
$oFrameC = _IEFrameGetObjByName($oFrameB, "results") 
$o_Input1 = _IEGetObjById($oFrameC, "SaProperty.NewHndlgCd")
$o_Input2 = _IEGetObjById($oFrameC, "SaProperty.AcctNbr")

_IEFormElementOptionselect ($o_Input1, "BWK-SANFR" , 1, "byText") 
;-----------------------------------------------------------------------------
;Submit Account Number
;-----------------------------------------------------------------------------
_IEFormElementSetValue ($o_Input2, "Damn")

$oInputs1 = _IETagNameGetCollection ($oFrameC, "input")      
For $oInput1 In $oInputs1
    If $oInput1.value = "Submit" Then
        ExitLoop
    EndIf
Next

_IEAction($oInput1, "click")

post-65075-0-20846700-1306957052_thumb.j

post-65075-0-29682300-1306957059_thumb.j

Link to comment
Share on other sites

I've attached the script I have created so far, the issue I am having is towards the end "_IEFormElementSetValue ($o_Input2, "Damn")". Instead of "DAMN", I want it to paste the account number from the spreadsheet, and continue to the next account number, until it ends.

So what exactly is the issue you need help with? I don't see any loop at all, or is the problem you don't know how to go about the loop?

Referring back to the beginning of your script, you have these lines:

$aArray1 = _ExcelReadSheetToArray($oExcel,2,3,0,1,True)
_ExcelBookClose($oExcel)
$rows = UBound($aArray1)-1

Check the Help File for _ExcelReadSheetToArray(). Instead of UBound(), try using $aArray1[0][0] which is the row count.

You can use a For loop to go thru each row...

For $i = 1 To $rows
    $iFullAcct = $aArray1[$i][0]
    ; Put code here to deal with the FULLACCT number
Next    ; On to the next

After every time you input the account number then submit that form, you may lose your reference to the account number field ($o_Input2) depending on how that page is set up.

Edit: Forgot some code tags

Edited by MrMitchell
Link to comment
Share on other sites

So what exactly is the issue you need help with? I don't see any loop at all, or is the problem you don't know how to go about the loop?

Referring back to the beginning of your script, you have these lines:

$aArray1 = _ExcelReadSheetToArray($oExcel,2,3,0,1,True)
_ExcelBookClose($oExcel)
$rows = UBound($aArray1)-1

Check the Help File for _ExcelReadSheetToArray(). Instead of UBound(), try using $aArray1[0][0] which is the row count.

You can use a For loop to go thru each row...

For $i = 1 To $rows
    $iFullAcct = $aArray1[$i][0]
    ; Put code here to deal with the FULLACCT number
Next    ; On to the next

After every time you input the account number then submit that form, you may lose your reference to the account number field ($o_Input2) depending on how that page is set up.

Edit: Forgot some code tags

Thank you again for the response. What I am trying to accomplish is this:

1-Copy the excel column to an array ( I believe I have that covered)

2-Open the site, paste the first account number from the array to the 'SaProperty.AcctNbr' object ID and update, or "submit"

3-Go back to the array, read the next available account number (next row) and follow step 2 and continue this loop until there are no more rows to read on the array.

I was able to create the following script which reads each row and gives me the next account number in the array via a message box, I want to follow the same process, but instead of giving me a message, I want to copy it to the web form.

#include <Array.au3>
#include <Excel.au3>
#Include <Clipboard.au3>
#include <String.au3>

local $oExcel = _ExcelBookOpen("C:\BBWK\export1SF.xls")
$aArray1 = _ExcelReadSheetToArray($oExcel,2,3,0,1)
_ExcelBookClose($oExcel)


For $r=1 To UBound($aArray1,1)-1
     For $c=1 to UBound($aArray1,2)-1
        MsgBox(0,"",$aArray1[$r][$c])
    Next
Next

I hope this somehow clarifies what I am trying to do.

Thanks again for your patience.

Link to comment
Share on other sites

Yes, perfectly clear.

You have this (note what has been added):

For $r=1 To UBound($aArray1,1)-1
    For $c=1 to UBound($aArray1,2)-1
        $aVariable = $aArray1[$r][$c]   
        ;Now you create a separate function to input the number into the form and hit submit and pass $aVariable as the account number.
        ;For example
        ;_UpdateAcctNum($aVariable)
        ;MsgBox(0,"",$aArray1[$r][$c])
        MsgBox(0,"",$aVariable)
    Next
Next

Like I said, depending on what happens after you click submit, you may need to get references to all your IE control again (for example $o_Frame, $oFrameB, $oFrameC, $oInput_1, etc...)

Edited by MrMitchell
Link to comment
Share on other sites

Yes, perfectly clear.

You have this (note what has been added):

For $r=1 To UBound($aArray1,1)-1
    For $c=1 to UBound($aArray1,2)-1
        $aVariable = $aArray1[$r][$c]   
        ;Now you create a separate function to input the number into the form and hit submit and pass $aVariable as the account number.
        ;For example
        ;_UpdateAcctNum($aVariable)
        ;MsgBox(0,"",$aArray1[$r][$c])
        MsgBox(0,"",$aVariable)
    Next
Next

Like I said, depending on what happens after you click submit, you may need to get references to all your IE control again (for example $o_Frame, $oFrameB, $oFrameC, $oInput_1, etc...)

MrMitchell, thanks once again for your help, I am able to paste the account number to the web form, and you were absolutely right, I do need to reference my IE controls again. After I click submit, a new page appears saying the account has been accepted. Afterwards, I choose the link to get me back to submit the next account number and try to loop the process, this is where I receive the following error:

--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IETagNameGetCollection, $_IEStatus_InvalidObjectType

C:\Excel5B.au3 (74) : ==> Variable must be of type "Object".:

For $oInput1 In $oInputs1

For $oInput1 In $oInputs1^ ERROR

Any help with this is greatly appreciated. I am attaching the "loop" script I have. Basically, I am trying to submit the account number, go back to the webpage, and re-submit the next account number.

$i=0
Do 
    $i=$i+1
    
Sleep (1000)
$o_frame = _IEFrameGetObjByName ($oIE, "launcher")
$oFrameB = _IEFrameGetObjByName($oIE, "target" )
$oFrameC = _IEFrameGetObjByName($oFrameB, "results") 
$o_Input1 = _IEGetObjById($oFrameC, "SaProperty.NewHndlgCd"); either BWK-SANFR or BWK-BOSTN
$o_Input2 = _IEGetObjById($oFrameC, "SaProperty.AcctNbr")
Sleep (500)
_IEFormElementOptionselect ($o_Input1, "BWK-SANFR" , 1, "byText") ; either BWK-SANFR or BWK-BOSTN

Sleep (2000)

 For $r=1 To UBound($aArray1,1)-1
    For $c=1 to UBound($aArray1,2)-1
        $aVariable = $aArray1[$r][$c]   
        $Account = ($aVariable)
        
_IEFormElementSetValue ($o_Input2, $Account)

$oInputs1 = _IETagNameGetCollection ($oFrameC, "input") 

Sleep (1000)
 
 For $oInput1 In $oInputs1
    If $oInput1.value = "Submit" Then
        ExitLoop
    EndIf
Next
_IEAction($oInput1, "click")

Sleep (5000)
WinActivate ("Sagent WebLink - Windows Internet Explorer")
Sleep (1000)
_IELinkClickByIndex ($o_frame, 0);Update Customer Link 
Next
 Next
Until $i = 5
Exit
Link to comment
Share on other sites

No need to respond, I have figured it out.

I just needed to move some of the script lines around to fit into the loop.

Thanks all for your help, especially, MrMitchell.

Next, I am going to work on a GUI, where the data entry person enters a number, and this would determine how many times the script will loop, but that would be for another thread.

I've attached the script I've corrected below in case any one else has a similar situation.

For $r=1 To UBound($aArray1,1)-1
        $o_frame = _IEFrameGetObjByName ($oIE, "launcher")
        $oFrameB = _IEFrameGetObjByName($oIE, "target" )
        $oFrameC = _IEFrameGetObjByName($oFrameB, "results") 
        $o_Input1 = _IEGetObjById($oFrameC, "SaProperty.NewHndlgCd"); either BWK-SANFR or BWK-BOSTN
        $o_Input2 = _IEGetObjById($oFrameC, "SaProperty.AcctNbr")
        Sleep (500)
        _IEFormElementOptionselect ($o_Input1, "BWK-SANFR" , 1, "byText") ; either BWK-SANFR or BWK-BOSTN
        Sleep (2000)
    For $c=1 to UBound($aArray1,2)-1
        $aVariable = $aArray1[$r][$c]   
        $Account = ($aVariable)     
        _IEFormElementSetValue ($o_Input2, $Account)
        
Sleep (3000)

$oInputs1 = _IETagNameGetCollection ($oFrameC, "input") 

Sleep (1000)
 
 For $oInput1 In $oInputs1
    If $oInput1.value = "Submit" Then
        ExitLoop
    EndIf
Next

Sleep (500)
_IEAction($oInput1, "click")

Sleep (5000)
WinActivate ("Sagent WebLink - Windows Internet Explorer")
Sleep (1000)
_IELinkClickByIndex ($o_frame, 0);Update Customer Link 
Sleep (2000)
Next
 Next
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...