Jump to content

Website Auto login - Variable Must Be Of Type Object?


Recommended Posts

Hello all,

First off, let me apologize if this is a dumb question. I've been digging through these forums all morning hoping that I could resolve this myself but I can't seem to figure it out. So for a work project I have a website I need to auto-login (via IE 8) and then navigate to a specific page to be displayed on a monitor.

The code I have thus far is as follows:

#include <IE.au3>

Local $oUser, $oPass, $oSubmit
Local $sUser = "myuser"
Local $sPass = "mspass"
Local $url = "http://10.10.10.10:8080/login/"
Local $oIE = _IECreate($url)

_IELoadWait($oIE)

$oInputs = _IETagNameGetCollection($oIE, "input")
for $oInput in $oInputs
if $oInput.type = "text" And $oInput.name = "j_username" Then $oUser = $oInput
if $oInput.type = "password" And $oInput.name = "j_password" Then $oPass = $oInput
if $oInput.type = "submit" And $oInput.value = "Log In" Then $oSubmit = $oInput
if isObj($oUser) And isObj($oPass) And isObj($oSubmit) then exitloop
Next

$oUser.value = $sUser
$oPass.value = $sPass
_IEAction($oSubmit, "click")

_IELoadWait($oIE)

This code will successfully launch IE and navigate to the page I want. I went with the _IETagNameGetCollection because the "submit" button doesn't give a name or ID, so I couldn't use the _IEGetObjByName or ID. I did find a link to the IE Debug toolbar, and I have used that to verify that all of these fields/controls are of the correct type and that I'm using the correct names/values. I tried the AutoIt 1-2-3 examples, have watched youtube videos, tried some tutorials for IE from the forums, but I can't seem to get this working.

The specific problem I have when I try to run is:

C:\Documents and Settings\user\Desktop\test.au3 (19) : ==> Variable must be of type "Object".:

$oUser.value = $sUser

$oUser^ ERROR

It's my understanding this is because my variable isn't an object, but I can't understand why? I only started using AutoIt this morning, and I'm trying to get this script working in 4 hours, LOL (not my choice of deadline). Any assistance would be very appreciated, I just can't see where I'm going wrong here. :(

Link to comment
Share on other sites

It's possible that the variable is not being set. Maybe durring the loop, it's never defined.

Do some error handling with IsObj()

You can also put this line at the top, and then the function for com-error handling (more info on failure)

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Func _ErrFunc($oError) ; Com error handling
; Do anything here.
ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
         "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
         "err.description is: " & @TAB & $oError.description & @CRLF & _
         "err.source is: " & @TAB & $oError.source & @CRLF & _
         "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
         "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
         "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
         "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
         "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc ;==>_ErrFunc

post one of the nodes

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I'd suggesting adding a debug line to your loop to see if you are even working on the set of objects you think you are...

ConsoleWrite(_IEPropertyGet($oInput, "outerhtml")) & @CRLF)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I'd suggesting adding a debug line to your loop to see if you are even working on the set of objects you think you are...

ConsoleWrite(_IEPropertyGet($oInput, "outerhtml")) & @CRLF)

Dale

Hi Dale, thanks for the response! I tried adding that in at the top of the loop so I'd see it for each iteration, but it doesn't seem to be outputting to my console window. So then I tried just ConsoleWrite("1") inside of the loop and still got no output. So from that I'm guessing it must never enter the loop, which must mean there are no items in the collection?

I am not sure how that's possible, because in the IE Debug toolbar I can see all these tagged as input:

Posted Image

I'm not very familiar with website/webpage design, but is there something in your knowledge that I might look for?

Thank you again!!!

Link to comment
Share on other sites

Hi Dale, thanks for the response! I tried adding that in at the top of the loop so I'd see it for each iteration, but it doesn't seem to be outputting to my console window. So then I tried just ConsoleWrite("1") inside of the loop and still got no output. So from that I'm guessing it must never enter the loop, which must mean there are no items in the collection?

I am not sure how that's possible, because in the IE Debug toolbar I can see all these tagged as input:

Posted Image

I'm not very familiar with website/webpage design, but is there something in your knowledge that I might look for?

Thank you again!!!

Hey guys, so it looks like it was due to having a frame with a form inside of it. So basically I had to get the frame, then get the form, then get the collection of controls on the form. Once I did that, it's now working and auto-logging in just fine! Thanks for the pointers! :)

Here's what I have that's working:

#include <IE.au3>

Local $oUser, $oPass, $oSubmit
Local $sUser = "myuser"
Local $sPass = "mypass"
Local $url = "http://10.10.10.10:8080/login/"
Local $oIE = _IECreate($url)

_IELoadWait($oIE)

$oFrame = _IEFrameGetCollection($oIE, 0)
$oForm = _IEFormGetCollection($oFrame, 0)

$oInputs = _IETagNameGetCollection($oForm, "input")
for $oInput in $oInputs
if $oInput.type = "text" And $oInput.name = "j_username" Then $oUser = $oInput
if $oInput.type = "password" And $oInput.name = "j_password" Then $oPass = $oInput
if $oInput.type = "submit" And $oInput.value = "Log In" Then $oSubmit = $oInput
if isObj($oUser) And isObj($oPass) And isObj($oSubmit) then exitloop
Next

$oUser.value = $sUser
$oPass.value = $sPass
_IEAction($oSubmit, "click")

_IELoadWait($oIE)
Edited by Oryx2046
Link to comment
Share on other sites

1. Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects:

  • Bypassing of security measures - log-in and security dialogs, CAPTCHAs, anti-bot agents, software activation, etc.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

  • Moderators

Blue_Drache,

Correct. But this is not a dialog - looks like a normal page as far as I can see. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Blue_Drache,

Correct. But this is not a dialog - looks like a normal page as far as I can see. ;)

M23

1. Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects:

  • Bypassing of security measures - log-in and security dialogs, CAPTCHAs, anti-bot agents, software activation, etc.

And if it helps, I own the webserver I'm logging into, so I'm not really bypassing so much as tailoring the application for a specific use. :)

Link to comment
Share on other sites

  • Moderators

Oryx2046,

That makes no difference at all as the required code would be generic and so available for others to use on other sites. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...