Jump to content
Sign in to follow this  
Tallcat

Login for a IE 2 page form

Recommended Posts

Tallcat

I am trying to figure out how to create a login for this webpage used for searching for environmental issues here in good old Saskatchewan. It is http://gisweb1.serm.gov.sk.ca/wildlifelogin/form.asp This is a 2 page login. This website times out very quickly so it is a pain to have to redo all parts of the 2 page form..

I have figured out how to do it with Webreplay Professional(http://www.iewatch.com/orderwr.aspx)(demo period is over) using the "xpath" and ajax and their web locate control bullseye.. No other macro recorder that I tried worked consistently on play back - so I'm trying this. I can send the whole thing privately.

To login you can use the "guest" and "password" defaults on title page(Wildlife Login.......) without a problem ((it just won't let you see the species data in popup from page 2 (CDC Wildlife-title))

Examples of the Web Replay "code"

Browser(1).Page("Wildlife Login......._2").Button("submit1").Click

start of page 2

Browser(1).Page("CDC Wildlife_18").Frame("tabFrame").Link("Layers").Click --- This actives the "layers" tab and opens a bunch of boxes and "tags" at the right side of the screen "the important items". This "Layers tab" is the most important item to activate on page 2.

Browser(1).Page("").WebControl("html/frameset/frameset[2]/frame/html/body/form/div/center/table[3]/tbody/tr/td[2]/a[5]/img" ).Click --- this one actives the "Rare and endangered species tag on the right side of the page --very important"

I am very new at Autoit and would like some help figure out how to use Autoit to get through the two pages and activate a number of the boxes and tags-- sure would make my work easier. Thanks for any help given to get me started. And as we say in Sask. "Go Riders" Football Season here starts July 1..

TC

Share this post


Link to post
Share on other sites
funkey

You could use my universal autologin-function.

#include <IE.au3>

$Url = 'http://gisweb1.serm.gov.sk.ca/wildlifelogin/form.asp'
$User = 'guest'
$Pwd = 'guest'

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

Func _IEAutoLogin($sUrl, $sUsername, $sPwd)
;funkey 09.09.09
$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

Edit:

Here is the special version for this page:

#include <IE.au3>

$Url = 'http://gisweb1.serm.gov.sk.ca/wildlifelogin/form.asp'
$User = 'guest'
$Pwd = 'guest'

$oIE = _IECreate($Url)
$oForm = _IEFormGetObjByName($oIE, "form1")
$oUserName = _IEFormElementGetObjByName($oForm, "Username")
$oPassword = _IEFormElementGetObjByName($oForm, "Password")

_IEFormElementSetValue($oUserName, $User)
_IEFormElementSetValue($oPassword, $Pwd)
_IEFormSubmit($oForm)

$oFrame = _IEFrameGetCollection ($oIE, 14)
_IENavigate($oFrame, "http://gisweb1.serm.gov.sk.ca/imf/imfLayers.jsp")
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
Tallcat

You could use my universal autologin-function.

I used your modified one and it works very good. THANKS!!!! :mellow: It Logs in and Opens the right side "Map Layers" and tags and check boxes. Please show me how to activate the "Rare and Endangered "tag" and the check box in the "township" part under the "Cadastre" folder, I think with those I'll be able to handle the other 10 or so tags and boxes. AGAIN THANKS. tc.

Share this post


Link to post
Share on other sites
funkey

Here it is. I changed the function _IEImgClick to _IEImgClickByIndex, so you can click the images only by index, because the checkboxes are images too, so I had to do so.

I hope it works for you.

Greetings from Austria.

#include <IE.au3>

$Url = 'http://gisweb1.serm.gov.sk.ca/wildlifelogin/form.asp'
$User = 'guest'
$Pwd = 'guest'

$oIE = _IECreate($Url)

WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_MAXIMIZE)

$oForm = _IEFormGetObjByName($oIE, "form1")
$oUserName = _IEFormElementGetObjByName($oForm, "Username")
$oPassword = _IEFormElementGetObjByName($oForm, "Password")

_IEFormElementSetValue($oUserName, $User)
_IEFormElementSetValue($oPassword, $Pwd)
_IEFormSubmit($oForm)

$oFrame = _IEFrameGetCollection($oIE, 14)
_IENavigate($oFrame, "http://gisweb1.serm.gov.sk.ca/imf/imfLayers.jsp")


#region Info
;~ _IEImgGetCollection($oFrame)
;~ $iNumImg = @extended
;~ For $i = 0 To ($iNumImg - 1)
;~  $oImg = _IEImgGetCollection($oFrame, $i)
;~  ConsoleWrite("Image Info: " & $oImg.src & " - " & $i & @CR)
;~ Next
#endregion Info

Sleep(2000)
_IEImgClickByIndex($oFrame, 4) ;uncheck Rare and Endangered Species
Sleep(2000)
_IEImgClickByIndex($oFrame, 4) ;check Rare and Endangered Species

Sleep(2000)
_IEImgClickByIndex($oFrame, 6) ;click Rare and Endangered Species - Active identify layer

Sleep(2000)
_IEImgClickByIndex($oFrame, 8) ;click Rare and Endangered Species - next image


Sleep(2000)
_IEImgClickByIndex($oFrame, 178) ;check township under Cadastre

;~ _IEQuit($oIE)


; #FUNCTION# ====================================================================================================================
; Name...........: _IEImgClickByIndex
; Description ...: Simulate a mouse click on an image.  Match by index
; Parameters ....: $o_object - Object variable of an InternetExplorer.Application, Window or Frame object
;       $i_index - Specify which instance you want to click by 0-based index
;       $f_wait  - Optional: specifies whether to wait for page to load before returning
;         0 = Return immediately, not waiting for page to load
;         1 = (Default) Wait for page load to complete before returning
; Return values .: On Success  - Returns -1
;               On Failure - Returns 0 and sets @ERROR
;     @ERROR  - 0 ($_IEStatus_Success) = No Error
;        - 1 ($_IEStatus_GeneralError) = General Error
;        - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type
;        - 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type
;        - 5 ($_IEStatus_InvalidValue) = Invalid Value
;        - 6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout
;        - 7 ($_IEStatus_NoMatch) = No Match
;        - 8 ($_IEStatus_AccessIsDenied) = Access Is Denied
;        - 9 ($_IEStatus_ClientDisconnected) = Client Disconnected
;     @Extended - Contains invalid parameter number
; Author ........: Dale Hohm, changed by funkey
; ===============================================================================================================================
Func _IEImgClickByIndex(ByRef $o_object, $i_index = 0, $f_wait = 1)
 If Not IsObj($o_object) Then
  __IEErrorNotify("Error", "_IEImgClick", "$_IEStatus_InvalidDataType")
  Return SetError($_IEStatus_InvalidDataType, 1, 0)
 EndIf
 ;
 Local $linktext, $found = 0, $imgs = $o_object.document.images
 $i_index = Number($i_index)
 For $img In $imgs
  If ($found = $i_index) Then
   $img.click
   If $f_wait Then
    _IELoadWait($o_object)
    Return SetError(@error, 0, -1)
   EndIf
   Return SetError($_IEStatus_Success, 0, -1)
  EndIf
  $found += 1
 Next
 __IEErrorNotify("Warning", "_IEImgClick", "$_IEStatus_NoMatch")
 Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 4 or both
EndFunc   ;==>_IEImgClickByIndex

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
Tallcat

Thanks FUNKEY got your PHD :mellow::P as we say here "you made me a happy camper".. I am gettin her built.. before you helped I monkeyed around with numerous ways labels, path, windetecthiddentext,etc etc.

I did make a mistake in my description of the "tags" they are are actually 'Labels' (they look like grey tags we tie on things) as in the one just right of the "Rare and Endangered Species" Layer name and it's index is =10 and that's the actual one I needed clicked on (I got her running)., it turns a lighter grey when active. May I ask how you figured out "the index" as I have a version started using "tabs" but it's very poor..

But as it's our "National Birthday today July 1' I'll only monkey around at bit more and than enjoy the day and watch "our Rough Riders" vs Montreal- play our version of "football"

I would like to be able to say hopefully I can help you someday, but not likely in this area; but I'm good at other things - just can't think of what they are now ha ha...

thanks AGAIN.. tallcat

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.