akibahsu

New to AutoIt, unsure if this works

8 posts in this topic

Hello everyone! I'm new to this and am willing to learn as I go along.

With the script below, I want it to Pixelsearch a certain color at a particular location. If it finds that color, it will activate Func Example(). If it doesn't find that color, then it will exit the While loop.

Will the below code work? 

 

While 1
   $Target = Pixelsearch
     If $Target = 1 Then 
        Func Example()
        Else ExitLoop
     EndIf
Wend

Thank you very much in advance! ^^

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

No. Pixelsearch returns a x and y coordinate array

$coord=pixelsearch (left,top,right,bottom,color)

If isarray ($coord) then

Example ()

Endif

Coord x is $coord [0] , coord y $coord [1]

Edited by markyrocks

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry, meant to post this instead:

While 1
   $Verify = Pixelsearch($Placeholder[0], $Placeholder[1], $Placeholder[2], $Placeholder[3], 0x000000, 0)
   If IsArray($Verify) = True Then
     Func Placeholder()
   Else
   
   ExitLoop
   
   EndIf
WEnd

I want this script to search an area for a color and if it finds it, to execute a Func Placeholder(). If it doesn't find that color, then it'll exit the While loop. Thank you very much for the help.

Edited by akibahsu

Share this post


Link to post
Share on other sites

Welcome to AutoIt and the forum!

Can you please tell us which application you try to automate?

Pixelsearch isn't always very reliable and there are - depending on the application - better ways to do what you want to do.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Welcome to AutoIt and the forum!

 

Thank you!  :)

Can you please tell us which application you try to automate?

Pixelsearch isn't always very reliable and there are - depending on the application - better ways to do what you want to do.

 

I'm trying to automate a web browser (Google Chrome). After clicking confirm/submit on a certain page, it may or may not (its random) move me to a page that says "Verification e-mail sent". On the page that says "Verification e-mail sent", there will be a color on that page at a specific location that I can Pixelsearch to confirm it is indeed the e-mail verification page. If it exists, I want to find it with Pixelsearch, access my e-mail and click on the verification link. If I'm not sent to the e-mail verification page, then I want it to ignore this.

I'm very new to this, but it is fun learning and I'm willing to take and see the various approaches that may accomplish this. Thanks for your help and here is my code:

Func VerifyEmail()
   
    $Verify = PixelSearch($Placeholder[0], $Placeholder[1], $Placeholder[2], $Placeholder[3], 0x000000, 0)
    If IsArray($Verify) = True Then
       GoEmail()
    EndIf
    
 EndFunc

Func GoEmail()
    MouseClick("LEFT", 0, 0, 1, 5) ;Clicks to open a new tab on Chrome
    Sleep($InputTime)
    MouseClick("LEFT", 0, 0, 1, 5) ;Clicks on address bar
    Sleep($InputTime)
    Send("gmail.com")
    Sleep($InputTime)
    Send("{ENTER}") ;Enters gmail
    Sleep($ChromeWaitTime)
    MouseClick("LEFT", 0, 0, 1, 5) ;Clicks on email link
    Sleep($ChromeWaitTime)
    MouseClick("LEFT", 0, 0, 1, 5) ;Clicks on verification link within the email
    Sleep($ChromeWaitTime + 5000) 
    MouseClick("LEFT", 0, 0, 1, 5) ;Closes the email tab
 EndFunc

The MouseClick coordinates have yet to be determined because I'm still unsure which resolution this script will be running in, but I'll add them in later when I get confirmation.

Edited by akibahsu

Share this post


Link to post
Share on other sites

'?do=embed' frameborder='0' data-embedContent>>

I recently found this. You may find it useful. It's really easier to use than it initially let's on. The simplespy.au3 gets objects from chrome,ff,IE then basically writes the code to manipulate the objects.

Share this post


Link to post
Share on other sites

I will look into it, thanks! 

I should have the rest of the code completed sometime tomorrow, so I'll be able to test it out and post my results here.

Share this post


Link to post
Share on other sites

Your code: 

Func VerifyEmail()
    $Verify = PixelSearch($Placeholder[0], $Placeholder[1], $Placeholder[2], $Placeholder[3], 0x000000, 0)
    If IsArray($Verify) = True Then
       GoEmail()
    EndIf
EndFunc

I like more:

Func VerifyEmail()
  Local $Verify=PixelSearch( $Placeholder[0],$Placeholder[1],$Placeholder[2],$Placeholder[3],0x000000,0 )
  If Not IsArray($Verify) Then Return SetError(2,0,0)
  Local $ecode=GoEmail()
Return($ecode)   
EndFunc

Or:

Func VerifyEmail()
  Local $Verify=PixelSearch( $Placeholder[0],$Placeholder[1],$Placeholder[2],$Placeholder[3],0x000000,0 )
  If Not IsArray($Verify) Then Return SetError(2,0,0)
Return(GoEmail())   
EndFunc

My english shucks, i know it.

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