Jump to content

Debugging


JayFran
 Share

Recommended Posts

I've been writing a script for the last few weeks and I'm finally finished. (NOTE:The majority of the script takes place on the internet explorer. )Now Dale told me before my code was buggy, since then I worked hard and fixed it drastically. Back then when I compiled it, it would run crappy. Since then my script runs great in source mode, however when i run it as exe sometimes i'll get error message on some line. I think its because of timing issues or loadwaits that are firing to early or late and the latter part of my code begins to execute without the elements being available since the page or whatever isn't fully loaded. On my pc it runs about 80%-99% thru on my colleague pc it my go about 20% - 85% when its complied as an executable. Is there any suggestions any one has to where I can tidy up and get rid of the bug in my code? Thanks in advance.

PS - I used the autoit3wrapper to help rewrite the majority of my code. Also, I want to maybe use some func's in my code... is it possible? I dont have a good understanding of them.

Here is my full script start to finish. It basically ask for credentials then logs a ticket via the internet.

#NoTrayIcon
#RequireAdmin

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_run_debug_mode=Y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <IE.au3>
#include<Debug.au3>

_IEErrorNotify (True)
AutoItSetOption("WinTitleMatchMode", 2);4
Opt("WinWaitDelay", 1000)
Opt("WinDetectHiddenText", 1)

; =================================================================================================
;                                           #UserName# 
; =================================================================================================
Do
    $user = InputBox("Login", "Enter Username:")
    If @error = 1 Then Exit
    If $user = "" Then MsgBox(16, "ISM Login", "Please Enter User Name")
    Until $user <> ""
    
$u_string = StringRegExp($user, "[a-z][0-9]|[:alpha:][@]{1}[u]{1}[s]{1}[.]{1}[i]{1}[b]{1}[m]{1}[.]{1}[c]{1}[o]{1}[m]{1}", 2)
If $u_string = @error Then MsgBox(5, "ISM Login", "Please Check the format of the username" & @CRLF & "Example: username@us.ibm.com")

; =================================================================================================
;                                           #Password# 
; =================================================================================================
Do
    $pass = InputBox("Password", "Enter Password:", "", "*")
    If @error = 1 Then Exit
    If $pass = "" Then MsgBox(16, "ISM Login", "Password in incorrect or blank")
    Until $pass <> ""
    
; =================================================================================================
;                                           #Ticket Numbers# 
; =================================================================================================
Do
$t_number = InputBox("Ticket Number", "Enter Ticket Number:" & @CRLF & "Example:1234")
If @error = 1 Then Exit
If $t_number = "" Then MsgBox(16, "ISM Login", "Enter Ticket Number:")
Until $t_number <> ""

$t_string = StringRegExp($t_number, "[0-9]", 1);[C](?i){1}
 If @error = 1 Then 
     MsgBox(5, "ISM Login", "Error in Ticket number")
     Exit
     EndIf
    
; =================================================================================================
;                                           #ISM Login# 
; =================================================================================================
Sleep(1000)
$oIE = _IECreate("https://129.39.231.133/maximo/webclient/login/login.jsp?appservauth=true")
$hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window
WinSetState($hIE, "", @SW_MAXIMIZE)
$oForm = _IEFormGetObjByName($oIE, "loginform")
$username = _IEGetObjById($oIE, 'j_username')
_IEFormElementSetValue($username, $user)
Sleep(1000)
$password = _IEFormElementGetObjByName($oForm, 'j_password')
_IEFormElementSetValue($password, $pass)
Sleep(1000)
$loginButton = _IEGetObjById($oIE,'loginbutton')
_IEAction($loginButton, "click")
$pause = _IELoadWait($oIE)
Sleep(2000)
; =================================================================================================
;                                           #Login Errors# 
; =================================================================================================
;If Error occurs
If $oIE = "https://129.39.231.133/maximo/webclient/login/j_security_check" Then $404 = _IEAttach("HTTP 404", "windowtitle")
            _IEAction($oIE, "refresh")
            
If $oIE <> _IEAttach("Start Center", "windowtitle") Then $oP = _IETagNameGetCollection($oIE, "button", 0)
            $return = _IEAction($oP, "click")
            
If $oIE = "https://129.39.231.133/maximo/ui/login" Then 
    Exit 
    EndIf;$sc = _IEAttach("Start Center", "windowtitle")
;           _IELoadWait($oIE)
    Sleep(2000)

; =================================================================================================
;                                           #ISM Home Page# 
; =================================================================================================
;Navigate to the ticket input 
_IELoadWait($oIE)
WinWait("Start Center - Windows Internet Explorer")
sleep(2000)
$c_click = "mx46"
$changes = _IEGetObjById($oIE, $c_click)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($changes, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep(1250)
$c_click2 = "menu0_CHANGE_MODULE_middle_anchor"
$changes2 = _IEGetObjById($oIE, $c_click2)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($changes2, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;sleep(1250)
$c_click3 = "menu7_CHANGE_APP_middle_anchor"
$changes3 = _IEGetObjById($oIE, $c_click3)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($changes3, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;sleep(1250)

Do
$done = _IEPropertyGet($oIE, "statusbar")
If $done <> "Done" Then Sleep(6000)
Until $done = "Done"  
; =================================================================================================
;                                           #ISM Ticket Field Fill & Lookup# 
; =================================================================================================
;Insert Ticket info
WinWait("Changes - Windows Internet Explorer")
Sleep(2000)
$ticketfill = _IETagNameGetCollection($oIE, "input")
$tid_0 = "mx398"
$tid_1 = "mx404"
For $Oticketfill In $ticketfill
Global $t_post = _IEPropertyGet($oIE, "innerhtml")
If $t_post = $tid_0 Then $Oticketfill = $tid_0
If $t_post = $tid_1 Then $0ticketfill = $tid_1
Next
$t_submit = _IEGetObjById($oIE, $t_post)
_IEAction($t_submit, "focus")
Send($t_number)
Send("{Enter}")
Sleep(3500)


$changetab = "Change"
$c_links = _IELinkGetCollection($oIE)
For $c_link in $c_links
    $cLinkText = _IEPropertyGet($c_link, "innerText")
    If StringInStr($cLinkText, $changetab) Then
        _IEAction($c_link, "click")
        ExitLoop
    EndIf
Next
_IELoadWait($oIE, 5000)
_IELoadWait($c_Link, 5000)
; =================================================================================================
;                                           #Ticket Upload# 
; =================================================================================================

;Sleep(15000)
;_IEAttach("Attachments", "html")
;$u_imageid0 = "mx847"
$u_imageid1 = "mx853"
$u_imageid2 = "Attachments"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerhtml")
    ;If StringInStr($sLinkText, $u_imageid0) Then
    ;    _IEAction($oLink, "click")
    ;     ExitLoop
   ; EndIf
     If StringInStr($sLinkText, $u_imageid1) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
    $uimg = _IEImgGetCollection($oIE)
        If $uimg = $u_imageid2 Then $oLink = $u_imageid2
        _IEImgClick($oIE, $u_imageid2, "alt", 0)
            ExitLoop
            
Next

Sleep(550)

$add_new_attach = "addnew_middle_anchor"
$a_n_a = _IEGetObjById($oIE, $add_new_attach)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($a_n_a, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
$add_file = "addnewfile_middle_anchor"
$a_f = _IEGetObjById($oIE, $add_file)
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($a_f, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;$pause = _IELoadWait($oIE)
Sleep(9000)

; =================================================================================================
;                                           #Iframe Window# 
; =================================================================================================

$oFrames = _IEFrameGetCollection ($oIE, 0)
$browse = _IETagNameGetCollection($oFrames, "input")
For $oBrowse In $browse
    $b_prop = _IEPropertyGet($obrowse, "innerhtml")
    If $b_prop = "file" Then $hit = $oBrowse
    Next
$b_open = _IEAction($oBrowse, "focus") ;can use click too to open the browse
Send("\\Phlh72600\techshare$\InventoryForm\C"&$t_number&".doc")
Sleep(1500)
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;_IELoadWait($oBrowse)
Sleep(12000)

; =================================================================================================
;                                           #Wrapping up# 
; =================================================================================================
$plantab0 = "Plans"
$plantab1 = "mx209_anchor"
$p_links = _IELinkGetCollection($oIE)
For $p_link in $p_links
    $pLinkText = _IEPropertyGet($p_link, "innerText")
        If StringInStr($pLinkText, $plantab0) Then
        _IEAction($p_link, "click")
        ExitLoop
    EndIf
    $pLinkstr = _IEGetObjById($p_link, $plantab1)
    If $pLinkstr = $plantab1 Then $p_link = $plantab1
    
Next
_IEAction($p_link, "focus")
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep(2000)
_IELoadWait($oIE)
Sleep(250)
$dm1 = "Detail Menu"
$dm2 = "mx5692[R:0]"
$dm3 = "mx3057[R:0]"
$detailmenu = _IEImgGetCollection($oIE)
For $detailmenu0 in $detailmenu
    $dmimg = _IEPropertyGet($detailmenu0, "innerText")
     If $dmimg = $dm1 Then
        _IEImgClick($detailmenu0, $dm1, "alt", 9)
        ExitLoop
    EndIf   
    $dmstr = _IEGetObjById($detailmenu0, $dm2)
    $dmstr = _IEGetObjById($detailmenu0, $dm3)
    If $dmstr = $dm2 Then $detailmenu0 = $dm2
    If $dmstr = $dm3 Then $detailmenu0 = $dm3
Next
$hwnd = _IEPropertyGet($oIE, "hwnd")
;_IEAction($dmstr, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep(1000)
;                                   #Details Sub Menu
$aat = _IELinkClickByText($oIE, "Go To Activities and Tasks")
Sleep(250)
_IELoadWait($oIE)


;                                   #Activities & Tasks (Plans Tab)
Sleep(250)
_IEAttach("Activities and Tasks", "windowtitle", 0)
$plan2_click0 = "Plans"
$plan2_click1 = "mx206_anchor"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $plan2_click0) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
    $sLinkStr = _IEGetObjById($oLink, $plan2_click1)
    If StringInStr($sLinkStr, $plan2_click1) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next
Sleep(250)

; =================================================================================================
;                                           #Change Status to Completed# 
; =================================================================================================
;<--------------Script Pauses------------------>
_IELoadWait($oIE)
Sleep(250)
WinActivate("Activities and Tasks - Windows Internet Explorer")
WinWaitActive("Activities and Tasks - Windows Internet Explorer")
_IEAttach("", "dialogbox")
Sleep(250)
$c_status0 = "mx5677[R:0]"
$c_status1 = "mx5671[R:0]"
$compstatus = _IETagNameGetCollection($oIE, "img")
For $compstatus0 In $compstatus
    $csid = _IEGetObjById($oIE, $c_status0)
    If $csid = $c_status0 Then $compstatus0 = $c_status0
    If $csid = $c_status1 Then $compstatus0 = $c_status1
     Next
Sleep(250)
_IEAction($csid, "focus")
$hwnd = _IEPropertyGet($oIE, "hwnd")
        ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep(1000)
$dd_click0 = "New Status";"mx8253"
;$dd_click1 = "mx8049"
$ddLinks = _IETagNameGetCollection($oIE, "input")
For $ddLink in $ddLinks
    $ddLinkText = _IEPropertyGet($ddLink, "innerText")
    If StringInStr($ddLinkText, $dd_click0) Then
        _IEAction($ddLink, "focus")
        ExitLoop
    EndIf
Next
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep(1000)
$dd_comp = "menu0_COMP_OPTION_middle_anchor"
$hit5 = _IEGetObjById($ddLink, $dd_comp)
_IEAction($hit5, "click")
Sleep(1500)
$c_button0 = "mx7863"
$c_button1 = "mx7857"
$completed = _IETagNameGetCollection($oIE, "button")
For $completed0 In $completed
    $cb_id = _IEGetObjById($oIE, $c_button)
        If $cb_id = $c_button0 Then $completed0 = $cb_id
        If $cb_id = $c_button1 Then $completed0 = $cb_id
        Next
_IEAction($cb_id, "click")


Func myexit()
    Exit
EndFunc
Edited by JayFran
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...