
maxlarue
Members-
Posts
9 -
Joined
-
Last visited
Everything posted by maxlarue
-
use the DOM. you can't look in IE.au3 for some examples of DOM usage Dim $pages[3] = ["www.1.com", "www.2.com", "www.3.com"] $ie = _IECreate("about:blank") For $page in $pages $ie.navigate($page) $elements = $ie.document.getElementsByTagName("a") for $element in $elements if isobj($element.firstChild) then if $element.firstChild.outerText = "Download" then $element.click() ;.... ;.... endif endif Next Next This should put you on the right path. read up on the DOM , (in any language - javascript uses it alot) to get more comfortable with using it.
-
Buttons with no form name or button name.
maxlarue replied to mianz's topic in AutoIt General Help and Support
<tr bgcolor='#FFFFFF'> <td class='txtbold' align='center'>18/10/2008<BR>Sat</td> <td></td> <td id='cell58_1' class='txtbold' align='center' bgcolor='white' onmouseover='doTooltip(event,0, "18/10/2008 (Sat)","2","09:15","09:45");' onmouseout="hideTip();"><input type="radio" id="58_1" name="slot" value="142233"></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> can be found by taking an approach like this $elements = $ie.document.getElementsByTagName("td") for $element in $elements if $element.outerText = "18/10/2008" then $element.nextSibling.nextSibling.Click() endif Next or if it will always have the id=58_1 then you can do $ie.document.getElementById("cell58_1").Click() not 100% sure about the click command, but finding the object is the hard part -
Buttons with no form name or button name.
maxlarue replied to mianz's topic in AutoIt General Help and Support
you'll need to use escape characters so that the whole thing becomes a string, right now it thinks its code somenode.previousSibling returns the DOM node which is 1 above the given node... so suppose i have like this <div images> <img1.... <img2... <img3... </div> then img2.parentNode is going to be the div, and img2.previousSibling is going to be img1, while img2. nextSibling is going to be img3 -
Buttons with no form name or button name.
maxlarue replied to mianz's topic in AutoIt General Help and Support
<td id='cell58_1' class='txtbold' align='center' bgcolor='white' onmouseover='doTooltip(event,0, "18/10/2008 (Sat)","2","09:15","09:45");' onmouseout="hideTip();"> <input type="radio" id="58_1" name="slot" value="142233"></td> $elements = $ie.document.getElementsByTagName("input") For $element in $elements If $element.previousSibling.getAttribute("onmouseover") = "'doTooltip(event,0, "18/10/2008 (Sat)","2","09:15","09:45");' Then $element.Click() endif Next or maybe like this ... If $element.parentNode.firstChild.getAttribute("onmouseover") = "'doTooltip(event,0, "18/10/2008 (Sat)","2","09:15","09:45");' Then ... do something like that, i can't be sure because i don't know what the page looks like once you get away from the ie.au3 functions you open yourself up to alot of flexibility for navigating the DOM -
HOW DO I SCAN FOR AN IMAGE ON A PAGE?
maxlarue replied to DaBoSS's topic in AutoIt General Help and Support
#include <IE.au3> HotKeySet("{ESC}", "terminate") $site = "www.google.com" ;you want to find an image, so its likely going to have certain info ;firebug is a firefox addon which lets you navigate the DOM (document object model) ;once you find a unique identifier for the button you want to press, do like this.. ;here are some example calls to the DOM ;this is what google's main search box looks like ;<input value="" title="Google Search" size="55" name="q" maxlength="2048"/> ;we'll write a generalized function to search for elements with unique attributes ;for instance, there are two attributes that look unique, name="q" and title="Google Search".. ;both of these are not likley to be found in a different input Func find_by_attr($ie, $tag, $attribute, $text) $temp_ie = _IEDocGetObj($ie) ;get all the DOM elements with tag input (for instance) ... those are the ones that look like <input value="".... $elements = $ie.document.getElementsByTagName($tag) ;parse the elements for the one your looking for, there might be more than one, look at IE.AU3 for some similar functions which allow you to specify an index For $element in $elements ;MsgBox(0, "", $element.getAttribute($tag)) $my_attribute = $element.getAttribute($attribute) If $my_attribute = $text Then ;this is an exact match, use StringInStr($my_attribute, $text) for substring matching return $element EndIf Next EndFunc ;an example call will look like this ; find_by_attr($ie, "img", "alt", "Submit") ;will find the first image element with alt="Submit" ; or for the example I gave with google, you could do it like this: ;find_by_attr($ie, "input", "name", "q") ;if your object has an ID, its really easy to access, as IDs MUST be unique. Names are not neccesarily unique though. An object can have an ID and a Name. ;$ie.document.getElementById("gbar");gets the gbar at the top of google.com ;now that you have the element, you need to click on it, this can be done by finding its position ; if the position is off the page, you'll need to write a function which detects it, and then scrolls down appropriately ; IE uses something like $ie.scrollTop and $ie.scrollLeft i believe, i'd need to double check, but i'm not going to if you don't need it ;so lets write a function to find the object on the screen, and another one to click it: func locate_center($object) $top = _IEPropertyGet($object, "screeny") $left = _IEPropertyGet($object, "screenx") $width = _IEPropertyGet($object, "width") $height =_IEPropertyGet($object, "height") ;xy coords of the CENTER of the object Dim $coords[2] = [ $left + $width / 2, $top + $height / 2] return $coords EndFunc ;now you can write a mouse function to move the mouse over the object and click it, ;this simulates exactly what a user would do func move($object, $click = 1) ;extra protection: if not IsObj($object) Then MsgBox(0, "", "failed to find object") terminate() EndIf $center = locate_center($object) MouseMove($center[0], $center[1]) if( $click = 1) Then MouseClick("left") EndIf EndFunc main() Func main() $ie = _IECreate($site) move(find_by_attr($ie, "input", "name", "q"), 1) Send("AutoIt Rocks") Send("{ENTER}") EndFunc func terminate() exit EndFunc hope this helps you'll need IE to do this, maybe version 7 i don't know, but you get the idea you can look at the IE.au3 files for more control if you don't want to get firebug, just click 'view source' on your browser, and find out what unique identifiers your button has. you don't need to search for it if it has an ID, or if its the only one if its kind, just do something like $ie.document.getElementById("Submit_Button") or if you know, for instnace that its the 4th input box in the 2nd form on the page what you can do is this: $ie.document.getEelementsByTagName("form").item(3).getElementsByTagName("input").item(2) notice, the arrays are 0-indexed this is probably more control than you need, but it may come in use for other ppl You'll have to write a loop with a 15 minute timer or whatever and call the find function each time while true sleep(900000);15min $testobj = find_by_attr($ie, "input", "name", "q") if isObj($testobj) then move($testobj);click on it, or do whatever else.... ;you can test if it moved to a different page by using $ie.locationURL or something ;for instnace if StringInStr($ie.locationURL, "www.google.com") then <do stuff> endif endif wend -
This should get you started. Although the hard part will be figuring out how to get it to work in the game. #include <Array.au3> HotKeySet("{PAUSE}", "main") HotKeySet("{ESC}", "terminate") Global $is_running = False ;build an array of all the possible buttons you want to be pressed ;look at http://www.ascii.cl/ for keys to send ;this adds 0-9 and spacebar (32) Dim $keys[1] = ["{ASC 32}"] for $i = 48 To 57 _ArrayAdd($keys, "{ASC " & $i & "}") Next While True Sleep(100) WEnd Func terminate() Exit EndFunc Func main() $is_running = Not $is_running while $is_running Sleep(Random(1000, 15000, 1)) Send($keys[Random(0, UBound($keys) - 1, 1)]) WEnd EndFunc
-
Help with a few functions and better coding.
maxlarue replied to xsnow's topic in AutoIt General Help and Support
Global $deposit = "C:\Documents and Settings\Parker\Desktop\BA\deposits.txt" Global $withdrawal = "C:\Documents and Settings\Parker\Desktop\BA\withdrawals.txt"is better written as the following, because you only have to change your path once if you move your folder off the desktop similarly, if you want to add another file reference, you don't have to type the absolute path. To access this you would just do : $path & $deposit Global $path = "C:\Documents and Settings\Parker\Desktop\BA\" Global $deposit = "deposits.txt" Global $withdrawal = "withdrawals.txt" $totaldeposits = $line[$i] + $totaldeposits can be re-written more succinctly as $totaldeposits += $line[$i] Func Deposit() $depositamount = Inputbox("Deposit", "How much?") If @Error = 1 Then MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered") Else If @Error = 0 Then $flag = Msgbox (4, "Is the information correct?", "Deposit of $"&$depositamount) If $flag = 6 Then FileWrite($deposit, $depositamount & @CRLF) EndIf EndIf EndIf EndFunc might be better rewritten as the following, although its slightly different, look at the comment Func Deposit() $depositamount = Inputbox("Deposit", "How much?") If @Error = 0 Then $flag = Msgbox (4, "Is the information correct?", "Deposit of $"&$depositamount) If $flag = 6 Then FileWrite($deposit, $depositamount & @CRLF) EndIf Else; if @error = 1 Then MsgBox(4096, "Deposit Canceled", "No Deposit Was Entered") EndIf EndFunc same goes for the other function Where they are now, you can probably turn your deposit withdrawal function into a single transaction function which takes different parameters, and then call your error messages from an array, or even from a different file. depends on how much you want to expand the program make sure you are consistent with indentation you have two EndFunc after the Deposit function I'm not sure why you declare all your variables at the top, although there's nothing wrong with it. As for me, I try to define things within the scope which they are used, such as depositamount, which i would define within deposit. You should always comment your code, and you shouldn't ever worry about optimization too early on. I recommend making a comment at the top of each function, as well as inline comments wherever you do some process which isn't immediately obvious. Also, I'd place some linebreaks to separate some of your code to make it more readable Oops, it double posted half way through, sorry -
AutoITX with Visual Basic 2008 Express
maxlarue replied to emf8003's topic in AutoIt General Help and Support
I haven't looked in to this yet, but at first glance I will suggest a work around: you might try wrapping this in an If statement which checks if the number of windows has increased. If it hasn't, then you can be pretty sure there was no pop-up, because there is such a small time frame for a different window to appear. -
#include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> HotKeySet("{F2}", "Chiudi") Opt('MustDeclareVars', 1) _Main() Func _Main() Sleep(10) Local $hGUI1, $hGUI2, $hImage, $hGraphic1, $hGraphic2,$PosM,$PosW,$xvar,$yvar;<<<<2 extra variables $hGUI2 = GUICreate("Zoomed", 400, 300, 0, 400, -1, $WS_EX_TOPMOST) GUISetState() _GDIPlus_Startup () Do $PosM = MouseGetPos() _ScreenCapture_Capture (@DesktopDir & "\GDIPlus_Image.jpg",$PosM[0] - 100,$PosM[1] - 100,$PosM[0] + 100,$PosM[1] + 100, False) $hImage = _GDIPlus_ImageLoadFromFile (@DesktopDir & "\GDIPlus_Image.jpg") $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND ($hGUI2) _GDIPlus_GraphicsDrawImageRectRect ($hGraphic2, $hImage, 0, 0, 200, 200, 0, 0, 400, 300) _GDIPlus_GraphicsDispose ($hGraphic2) _GDIPlus_ImageDispose ($hImage) $PosW = WinGetPos("Zoomed") ;___________________added code here____________________________ if $PosM[0] + 100 + 400 > @DesktopWidth Then $xvar = @DesktopWidth - 400 Else $xvar = $PosM[0] + 100 EndIf if $PosM[1] + 100 + 300 > @DesktopHeight Then $yvar = @DesktopHeight - 300 Else $yvar = $PosM[1] + 100 EndIf ;______________________________________________________________ WinMove("Zoomed", "",$xvar,$yvar) Sleep(10) Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc Func Chiudi() _GDIPlus_Shutdown () FileDelete(@DesktopDir& "\GDIPlus_Image.jpg") Exit EndFunc This fixes it, but don't grade it based on style