Jump to content

Stepping Through Autoit Code


 Share

Recommended Posts

Hello:

I'm self taught & fairly proficient at writing VB code in Excel and have found the ability to "step" through the code in VB editor to be an immense learning/ debugging tool. Basically you can hit F8 and step through the code line by line so that it is possible to watch what the code is doing (in excel in this case) line by line. You can also select a line of code and press ctl-F8 and have the code run to the cursor (nice for getting past loops).

My question is how do I do this using sciTE for autoIT scripting or is this possible using some other editor for autoIT?

I'm trying to figure out how DaleHolm has done what he's done in the below example because I have a similar situation in something I'm trying to use autoIt to automate. In other words I have to access an in-house system (html interface, accessing an oracle database) and need to click on checkboxes &/or boxes that show no contol i.d. using AU3INF.exe. I've printed out IE.au3 and read through the descriptions of the relevant IE functions, but I'm still not getting it.

This example opens the AutoIt forum search page and toggles the sortby radiobuttons. An identical technique can be used with checkboxes.

#include <IE.au3>

$oIE = _IECreate()

_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

$oFrom = _IEFormGetObjByName($oIE, "sForm")

$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)

$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

For $i = 1 to 5

$oRelevant.checked = True

Sleep(1000)

$oRecent.checked = True

Sleep(1000)

Next

http://www.autoitscript.com/forum/index.ph...opic=13398&st=0

some very helpful VB editor debug commands:

step into F8

step over

step out

run to cursor ctl-F8

Thanks!

Link to comment
Share on other sites

  • Moderators

Try viewing the source of your webpage and look for <form name="this vaule is what you are looking for">. The example you showed targets a form with the name "sForm". I provided a piece of the source from that example to help you understand what to look for.

<form action="http://www.autoitscript.com/forum/index.php?act=Search&CODE=simpleresults&mode=simple" method="post" name="sForm">
Link to comment
Share on other sites

Hello:

I'm self taught & fairly proficient at writing VB code in Excel and have found the ability to "step" through the code in VB editor to be an immense learning/ debugging tool. Basically you can hit F8 and step through the code line by line so that it is possible to watch what the code is doing (in excel in this case) line by line. You can also select a line of code and press ctl-F8 and have the code run to the cursor (nice for getting past loops).

My question is how do I do this using sciTE for autoIT scripting or is this possible using some other editor for autoIT?

I'm trying to figure out how DaleHolm has done what he's done in the below example because I have a similar situation in something I'm trying to use autoIt to automate. In other words I have to access an in-house system (html interface, accessing an oracle database) and need to click on checkboxes &/or boxes that show no contol i.d. using AU3INF.exe. I've printed out IE.au3 and read through the descriptions of the relevant IE functions, but I'm still not getting it.

This example opens the AutoIt forum search page and toggles the sortby radiobuttons. An identical technique can be used with checkboxes.

#include <IE.au3>

$oIE = _IECreate()

_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

$oFrom = _IEFormGetObjByName($oIE, "sForm")

$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)

$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

For $i = 1 to 5

$oRelevant.checked = True

Sleep(1000)

$oRecent.checked = True

Sleep(1000)

Next

http://www.autoitscript.com/forum/index.ph...opic=13398&st=0

some very helpful VB editor debug commands:

step into F8

step over

step out

run to cursor ctl-F8

Thanks!

first off, welcome to the forum. VB was one of my first languages too, and i can empathize that at first debugging scripts seems like more work. There are alot of ways to debug in SciTE though. here are a few things you can do to help track your script and your values during execution.

Opt("TrayIconDebug",1)
; the above line allows you to hover your mouse over the script's icon in the systray
; and see the line currently being interpretted at that time.  good for identifying loops
; that you may have set an invalid exit condition for.
Msgbox(0,"Value of", $variable)
; message boxes can be immeasurably helpful for tracking a value per iteration, 
; or just notifying you of the progress of your script during the debugging phase.
ConsoleWrite(@lf & $variable & " : Variable" & @lf)
;when you're running code from scite, that line sends information to the console window
;allowing you to see the same information you could have in a message box, without delaying 
;the script with an interrupting message box
ToolTip($variable)
; creates a tooltip at your mouse position, with whatever information you'd like.
; this is good when your script activates other windows and you can't keep an eye on the
; scite console.  i frequently use this for checking mouse colors, tracking counters, or
; just letting myself know exactly where i am in the script.

in scite's tools menu, there are alot of debugging and tracing options there so that you usually don't have to even write the lines above yourself (although i typically do so that i get exactly what i want formatted the way i want it) . also in scripts and scraps, i remember about 2 weeks ago (maybe 3?) someone also made an additional debugging tool, it looked like it may allow selecting execution similar to stepping, but i really didn't check it out very much.

Link to comment
Share on other sites

sorry, i went off on a debugging rant, and didn't address the explanation you were looking for...

#include <IE.au3>

that line allows you to call the functions in the ie.au3 file as if they were part of your script.

$oIE = _IECreate()

that function creates an instance of internet explorer, and assigns that instance a name you can use to reference that object.

_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

that function tells the named instance of IE to navigate to the page indicated

$oFrom = _IEFormGetObjByName($oIE, "sForm")

here he grabs the form object by name. in order to figure out the name, you'd just look for a name property in the source code of the page you intend to interact with.

$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)

this line is to create a reference to an element of the form. again the name he's using to get the object by name, "sortby", comes from the source of the page, it's not just an arbitrary name. alot of times if there are more than one checkbox or radio button, they will have the same name. in that case you could also use _IEFormElementGetObjByIndex(). here dale is using the '0' parameter to indicate that it is the first object with that name.

$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

the "1" here specifies the second object with the same name

For $i = 1 to 5
    $oRelevant.checked = True
    Sleep(1000)
    $oRecent.checked = True
    Sleep(1000)
Next

this loop just alternates the selection between the two checkboxes, but setting the .checked property of each, then waiting a second...

Link to comment
Share on other sites

Thank you cameronsdad!

I especially appreciated your code commentary.

This is a really powerful program.

:)

no problem man, always glad to help. for help getting started, i'd also suggest checking out Val's new user guide; it's got alot of good advice in there.
Link to comment
Share on other sites

  • 11 years later...

The question has been answered so it doesn't remain.

You cannot step through AutoIt code ala VBE, you have to insert the debugging break points yourself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

18 hours ago, BrewManNH said:

The question has been answered so it doesn't remain.

You cannot step through AutoIt code ala VBE, you have to insert the debugging break points yourself.

Yeah... I guessed so. I was just hopeful. I find that feature very useful but since it is not there I use DBug and output to console. Thanks BrewManNH.

---
vicsar
https://about.me/vicsar
 

 

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