Jump to content
Sign in to follow this  
JohnnyVolcom5

Help Fixing A Loop

Recommended Posts

JohnnyVolcom5

Hi All,

I am having some troubles.  I have a loop that moves the mouse until it finds a Hand cursor, OR moves more than 50 pixels.  If it finds a hand, it clicks the link and then does some stuff and returns to the same page it clicked only 15 pixels down (So now the hand is an arrow again).  It continues the loop and finds the next link if there is another one, but if there isnt another link the mouse travels more than 50 pixels but the loop doesnt exit.  

Hope i explained that well enough.  Here is the code.  

Global  $MousePosy, $x=701, $y= 657 ,$MouseCur, $s= 1700

MouseMove ($x, $y,0); Move right above where the units are listed.
Do
$y= MouseGetPos (1) ;Set $y to current Mouse Pos, x position is static

$MousePosy = MouseGetPos (1) ;Set $MousePosy to current Mouse Pos.

$MouseCur = MouseGetCursor () ;See if cursor is a hand or arrow

MouseMove ($x, $MousePosy + 1,1) ;move mouse down one pixel at a time

$MouseCur = MouseGetCursor () ;get cursor type

Until $MouseCur = 16 Or $MousePosy >= $y + 50 ;determine if cursor is now a Hand or mouse traved more than 50 pixels

    If $MouseCur = 16 Then ;it found a hand, click link and close RMA
 $y= MouseGetPos (1) ;set $y to where it found the link
MouseClick ("Left", $x, $y ) ;Click the link to close RMA
Sleep ($s) ;wait for load, going to change this to search for pixel color change instead of set sleep time
MouseClick ( "Left" , 910, 1261, 1,0) ;CLick Close
MouseClick ( "Left" , 1021, 1288, 1,0) ;Save and Submit
Sleep ($s)
MouseClick ( "Left" , 910, 648, 1,0);HotSwap Click
MouseClick ( "Left" , 1021, 1288, 1,0) ;Save and Submit
Sleep ($s)
MouseClick ( "Left" , 1400, 343, 1,0); This will return to the first page where the link was clicked
Sleep ($s)
MouseMove ($x, $y +15,0) ;move to where it clicked the link before, but go down 15 pixels to get off the perviously clicked link
$y= MouseGetPos (1) ;Set $y to new mouse pos
MsgBox (0,"",$y)
ContinueLoop ;now it looks for another link

Elseif $MousePosy >= $y + 50 Then ; if while searchign for link mouse travels 50 pixels or more, EXIT LOOP.  <<<<<<<<<<<<<<<<THIS PART DOESNT EVER HAPPEN

MsgBox (0,"","Done"); WHY YOU NO WORK, ARRRRRRGH!!!
ExitLoop
EndIf

It finds and clicks all the links like it should, but it will not exit loop if it didnt find a link within 50 pixels.  

Sorry if code is poorly organized, i am noob. 

Share this post


Link to post
Share on other sites
BrewManNH

Are you using this to automate a webpage? Have you tried the _IE* functions to do it?


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

Share this post


Link to post
Share on other sites
JohnnyVolcom5

Are you using this to automate a webpage? Have you tried the _IE* functions to do it?

 

Yes for some webpage automation.  Unfortunately this page doesnt work very well with IE.  The site is poorly designed which is why i need to script this in the first place. xD

Thanks for your input though! 

Share this post


Link to post
Share on other sites
JohnnyVolcom5

Well never mind, i managed to figure it out. 

Here is the fixed code in case anyone is wondering what i ended up with.  

Global  $MousePosy, $x=701, $y= 657 ,$MouseCur, $s= 1700
MouseMove ($x, $y,0); Move right above where the units are listed.
$z= $y +50 ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<This is fix
Do

$y= MouseGetPos (1) ;Set $y to current Mouse Pos, x position is static

$MousePosy = MouseGetPos (1) ;Set $MousePosy to current Mouse Pos.

$MouseCur = MouseGetCursor () ;See if cursor is a hand or arrow

MouseMove ($x, $MousePosy + 1,1) ;move mouse down one pixel at a time

$MouseCur = MouseGetCursor () ;get cursor type


Until $MouseCur = 16 Or $MousePosy = $z ;determine if cursor is now a Hand or mouse traved more than 50 pixels  <<<<other part of fix

    If $MouseCur = 16 Then ;it found a hand, click link and close RMA
 $y= MouseGetPos (1) ;set $y to where it found the link
MouseClick ("Left", $x, $y ) ;Click the link to close RMA
Sleep ($s) ;wait for load, going to change this to search for pixel color change instead of set sleep time
MouseClick ( "Left" , 910, 1261, 1,0) ;CLick Close
MouseClick ( "Left" , 1021, 1288, 1,0) ;Save and Submit
Sleep ($s)
MouseClick ( "Left" , 910, 648, 1,0);HotSwap Click
MouseClick ( "Left" , 1021, 1288, 1,0) ;Save and Submit
Sleep ($s)
MouseClick ( "Left" , 1400, 343, 1,0); This will return to the first page where the link was clicked
Sleep ($s)
MouseMove ($x, $y +15,0) ;move to where it clicked the link before, but go down 15 pixels to get off the perviously clicked link
$y= MouseGetPos (1) ;Set $y to new mouse pos
MsgBox (0,"",$y)
ContinueLoop ;now it looks for another link

Elseif $MousePosy = $z Then ; if while searchign for link mouse travels 50 pixels, then there are no more unit<<<<<other part of fix

ExitLoop
EndIf
Next


MsgBox (0,"","Done")
Edited by JohnnyVolcom5

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  

×