Jump to content

New to AutoIt, unsure if this works


Recommended Posts

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! ^^

Link to comment
Share on other sites

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
Link to comment
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.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.

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