Cyberjunk

Web page automation (Fixed)

9 posts in this topic

#1 ·  Posted (edited)

Hello, I am new to both Programming and this forum. I have done a few tiny projects that were successful and fell in love with Autoit. So now I am trying to learn new things as I go. I have read the Help docs on my following question, I have gone thru all of that. and I am sure as soon as you see my code you will be saying OMG why did he do that, or OMG how can you forget to add this.. But when your new you take the path of least resistance to get the outcome you want.

SETUP:

I am trying to make a code that will open a piece of software, then open a browser (which has a handful of tabs already open) go to a web page (one of the tabs) and search an area of the web page for a specific color, if that color is found I want it to close the browser and go back and start again. If that color is not found on that page I want it to switch tabs and search that page for the color. If the color is found on that page I want it to close the browser and start again. If the color is not found on either page, I want it to open another browser and go to website and do some things I will add once i get past this obstacle.

I already have it almost there my code will open my software, open the browser, do the searches, find or not find the color, the part I am having trouble with is the if and else and what happens if and what it does if it does not. So the first code I have does everything I want except if it finds the color on the first run it closes the browser, but then when it starts the process again it doesnt check for the color. its like it skips the scanning part and goes straight to the opening of the second browser and finishes the code.

Run( "C:\Programs\myprogram.exe", "", @SW_SHOWDEFAULT )
Sleep(4000)
MouseClick("left", 613,272) ;click in program
Sleep(500)
Example()
Func Example()
    MouseClick("left", 632,456) ;click in program
Sleep(500)
MouseClick("left", 527,456) ;click in program
Sleep(15000)
Run( "C:\Programs\browser1.exe", "", @SW_SHOWMAXIMIZED )
Sleep(Random(4000,6000))
EndFunc   ;==>Example
MouseClick("left", 162,14) ;switch tab
Sleep(Random(5000,8000))
MouseClick("left", 354,14) ;switch tab
Sleep(Random(5000,8000))
$aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color
If Not @error Then
    MouseClick("left", 1338,6) ;close browser1
Sleep(1000)
Call("Example")
Else
    MouseClick("left", 162,14) ;switch tab 
    Sleep(1000)
EndIf
MouseClick("left", 162,14) ;click tab again just to be sure its loaded
Sleep(4000)
$aCoord = PixelSearch(1052, 308, 1120, 431, 0xFF0000, 10) ;search for this color
If Not @error Then
    MouseClick("left", 1338,6) ;close browser1
Sleep(1000)
Call("Example")
Else
    Run( "C:\Programs\browser2.exe", "", @SW_SHOWMAXIMIZED )
    Sleep(2000)
EndIf
MouseClick("left", 134,45) ;click on address bar
Sleep(1000)
Send("aspecificwebpage.com") ;input website
Send("{enter}") ;hit enter
Sleep(15000)
MouseClick("left", 1338,6) ;close browser2
Sleep(500)
MouseClick("left", 1338,6) ;close browser1
Sleep(500)
MouseClick("left", 625,454) ;click in program
Sleep(500)
MouseClick("left", 634,271) ;click in program
Sleep(500)
MouseClick("left", 917,245) ;close program
Sleep(500)

SO it makes the first scan and is successful, if the color is found it closes as I want, but then when nit starts the code again it does not scan anything the second time.

and on the other side, if the color is not found naturally everything works as it is written.

I want to guess by all the weird colors in the code sniplet I have a massive amount of errors. It is like a rainbow of text up there. different from what i see in AutoIT


Any help would be appreciated.

 

Edited by Cyberjunk
Amended title

Share this post


Link to post
Share on other sites



#2 ·  Posted

Cyberjunk,

Welcome to the AutoIt forums.

Firstly, please give your future threads meaningful titles - everyone who posts in the "General Support" section needs assistance!

Secondly, bravo for having correctly used code tags to post your code - the colours you see are the forum automatically converting the code to the standard syntax colouring used by the SciTE editor that is installed along with AutoIt. You might find it useful to download and install the full SciTE4AutoIt3 package which lets you create your own colour scheme as well as offering lots more utilities to help you code in AutoIt.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

2 minutes ago, Melba23 said:

Cyberjunk,

Welcome to the AutoIt forums.

Firstly, please give your future threads meaningful titles - everyone who posts in the "General Support" section needs assistance!

Secondly, bravo for having correctly used code tags to post your code - the colours you see are the forum automatically converting the code to the standard syntax colouring used by the SciTE editor that is installed along with AutoIt. You might find it useful to download and install the full SciTE4AutoIt3 package which lets you create your own colour scheme as well as offering lots more utilities to help you code in AutoIt.

M23

I was not sure how to title it, I will do better in the future. I dont think i can edit the title so it will have to stay the way it si for now I guess.

Actually it was just in the forum code editor, once the post was published it all matches my regular AutoIT Program. I am not worried about the colors actually. Just when I put the code in the editor here it was all so colorful and I assumed it was because of all my mistakes. Like if you put an ' in html some editors will change all text after that to the color blue or until another ' is found. notifying you some kind of argument is expected or missing.

I just downloaded the AutoIT the other day so i think it should be all updated, unless that package is an extra package for AutoIT. Customizing the colors in my SciTE is not an issue I am fine with what is provided, but if there are other thngs I may not have in that package that may be of interest in the future.

Thank you for your quick response.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Cyberjunk,

I will amend the title for you - you can do it in future by editing the OP.

The forum code editor does indeed give you some funny colours when you paste code - but it usually sorts itself out when posted.

SciTE4AutoIt3 is indeed an "extra" package - and very highly recommended by all who use it.

Finally, when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

2 minutes ago, Melba23 said:

by editing the OP.

Im having trouble finding this as well...


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#6 ·  Posted

Yes I dont have permissions to edit anything yet, (or I would delete that quote as well) most forums do not allow you to edit your posts or anything until you have met a certain level.

Share this post


Link to post
Share on other sites

#7 ·  Posted

23 minutes ago, Melba23 said:

 You might find it useful to download and install the full SciTE4AutoIt3 package .............

I actually already have it installed. I just checked. I downloaded 2 things the other day Autoit-v3-setup.exe and SciTE4AutoIt3.exe. I wanted to make sure I had the compiler and Win info.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ok so I think I finally got it. It must have been pretty complicated as no one responded to the actual coding question. But for future reference since the goto command was deprecated (just WOW) it seems now you have to do 3 times the work (Mostly research to find how to replace the GOTO), and create a custom function for every action in your code. Then you write the actual program code to call every function in the exact order you need them in. Then be careful because if your functions are in the wrong place you will create a loop in your program. I would have rather had the option to use GOTO because it was needed for this specific situation. That loop took me forever to find and fix. It just kept looping the last part of my code. For every time the else was found in either option, it made a loop of just the last part.

But anyways here is how I fixed it.... Is it correct, Yep it runs! is it right Probably not, I am sure for those who look and are actually experienced, laughs will fill their rooms. but hey man, I did what i could to get it to work.

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit
EndFunc   ;==>Terminate
Func CloseB1()
    MouseClick("left", 1338,6) ;close browser1
    Sleep(500)
    MouseClick("left", 632,456) ;click in program
    Sleep(500)
    MouseClick("left", 527,456) ;click in program
    Sleep(15000)
EndFunc   ;==>CloseB1
Func Tab2()
    MouseClick("left", 354,14) ;switch tab
    Sleep(Random(5000,8000))
    $aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color
If Not @error Then
    Call("CloseB1")
Else
    Call("Browser2")
EndIf
EndFunc   ;==>Tab2
Func Browser2()
    Run( "C:\Programs\browser2.exe", "", @SW_SHOWMAXIMIZED )
    Sleep(2000)
    MouseClick("left", 134,45) ;click on address bar
    Sleep(1000)
    Send("aspecificwebpage.com") ;input website
    Send("{enter}") ;hit enter
    Sleep(15000)
    MouseClick("left", 1338,6) ;close browser2
    sleep(500)
    MouseClick("left", 1338,6) ;close browser1
    Sleep(500)
    MouseClick("left", 625,454) ;click in program
    Sleep(500)
    MouseClick("left", 634,271) ;click in program
    Sleep(500)
    MouseClick("left", 917,245) ;close program
    Sleep(500)
EndFunc ;==>CloseBrowser2
Run( "C:\Programs\myprogram.exe", "", @SW_SHOWDEFAULT )
Sleep(4000)
MouseClick("left", 613,272) ;click in program
Sleep(500)
MouseClick("left", 632,456) ;click in program
Sleep(500)
MouseClick("left", 527,456) ;click in program
Sleep(15000)
Call(Browser1)
Func Browser1()
Run( "C:\Programs\browser1.exe", "", @SW_SHOWMAXIMIZED )
Sleep(Random(4000,6000))
MouseClick("left", 162,14) ;switch tab
Sleep(Random(5000,8000))
MouseClick("left", 354,14) ;switch tab
Sleep(Random(5000,8000))
$aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color
If Not @error Then
    Call("CloseB1")
Else
    Call("Tab2")
EndIf
EndFunc   ;==>Browser1


Thoughts would be appreciated.
 

 

Edited by Cyberjunk

Share this post


Link to post
Share on other sites

Hi

I think the purpose of what you are trying to do is perhaps a bit obscured by the fact that the web page is not identified.

Have you looked at the _IE automation examples in the HelpFile?

A few ideas, this is not a rewrite of your script, rather just some things to consider:

; Open browser to the AutoIt homepage, loop through the links
; on the page and click on the link with text "overview"
; using a sub-string match.

#include <IE.au3>

Local $oIE = _IECreate("http://www.autoitscript.com")

Local $sMyString = "overview"
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

:)

 


Skysnake

Why is the snake in the sky?

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

  • Similar Content

    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • mati
      By mati
      Hi,
      I wonder if
      AutoIt3Wrapper_run_debug_mode = Y can include run information about functions which are called within the main code. So far I noticed in the console that the function itself is called but no specific run information from  inside the function is provided. Is there a chance to show the entire debug log including functions in the console?
      I furthermore noticed a stop of information when a loop is entered. What could be the reason for that?
       
      Thanks for help.
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • hcI
      By hcI
      Hello, i'm making a little script that lets users enter a question and if the script can't answer to, it ask what would be the answer (a bit like siri on IPhones). And I try to display the "supposed array" I still have an error.. I searched on Google and got nothing looked in the help file too.. I'm here to know if someone have a solution to my error please.
      Here is where $a and $b should become arrays :
      Dim $dossier = @AppDataDir & "\Siri2" Dim $chemin = $dossier & "\data.ini" Global $a = _InfoRead($chemin, 0) Global $b = _InfoRead($chemin, 1) with this function :
      Func _InfoRead($path, $mode = 0) If DirGetSize($dossier) = -1 Then Return SetError(-4) If Not FileExists($chemin) Then Return SetError(-5) Local $readed = IniReadSection($path, "data") If @error Then Return SetError(-3) $size = $readed[0][0] Local $return[$size] For $i = 1 To $size Step 1 $return[$i - 1] = $readed[$i][$mode] Next Return $return EndFunc and the thing that i don't understand is that, after _InfoRead return affected to $a, I can't use _ArrayDisplay because of  error 1 "$aArray is not an array" (and same fpr the variable $b)..
      Can please someone help me to understand why is it doing this ?

      -hcI
    • kawliga751
      By kawliga751
      I'm new to Auotit but I have built a simple script that "runs" a different "batch" file based on certain days of the workweek. The script works now, but I was wanting to eliminate the need for a manual date entry. For example "First Batch' needs to run every Tuesday thru Thursday however "Second Batch" needs to run only on Friday and "Third Batch" needs to run only on Monday. In addition the 1st batch file runs on Tuesday, say 06/06 (the "FW" section) but then needs to actually report (the F4 date) the next weekday so this Batch actually needs 2 dates verified. 
      What I'm trying to do is when the script is initiated it gets the date, verifies if and which weekday it is and in turn goes to and runs the appropriate "Batch' file.  
      I've found ways to verify weekdays but can't find anything to do all of the above.
      Any help is MUCH appreciated.
       
      ;P10
      ShellExecute("C:\Program Files (x86)\Ericom Software\PowerTerm Enterprise\Sessions\mir00p10.PTS")

      WinWait('(A) Soutwest P10 : PowerTerm Pro Enterprise Suite')
      WinActivate('(A) Soutwest P10 : PowerTerm Pro Enterprise Suite')
      Send('$Login)
      Sleep(3000)
      Send('{Enter}')
      Sleep(3000)
      Send($Password)
      Send('{Enter}')
      Sleep(3000)
      ; ****First Batch file run
      Send('Batch')
      Sleep(3000)
      Send('{Enter}')
      Send('FW')
      Send('{Enter}')
      Send('{DOWN}')
      Send($Date)
      Send('{Enter}')
      Send('{Enter}')
      Send($Date)
      Send('{F9}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send('{F4}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send($Date)
      Send('{Enter}')
      Send('0620')
      Send('{Enter}')
      SEND('{!}SW0410PM.FWR')
      Send('{Enter}')
      Sleep(3000)
      Send('Y')
      Send('{Enter}')
      Sleep(3000)
      Send('{F9}')
      Sleep(3000)
      ; ****Second Batch file run
      Send('Batch')
      Sleep(3000)
      Send('{Enter}')
      Send('FW')
      Send('{Enter}')
      Send('{DOWN}')
      Send($Date)
      Send('{Enter}')
      Send('{Enter}')
      Send($Date)
      Send('{F9}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send('{F4}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send($Date)
      Send('{Enter}')
      Send('0620')
      Send('{Enter}')
      SEND('{!}SO0411AM.FWR')
      Send('{Enter}')
      Sleep(3000)
      Send('Y')
      Send('{Enter}')
      Sleep(3000)
      Send('{F9}')
      Sleep(3000)
      ; ****Third Batch file run
      Send('Batch')
      Sleep(3000)
      Send('{Enter}')
      Send('FW')
      Send('{Enter}')
      Send('{DOWN}')
      Send($Date)
      Send('{Enter}')
      Send('{Enter}')
      Send($Date)
      Send('{F9}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send('{F4}')
      Send('Y')
      Sleep(3000)
      Send('{Enter}')
      Send($Date)
      Send('{Enter}')
      Send('0620')
      Send('{Enter}')
      SEND('{!}SW0411AM.LOA')
      Send('{Enter}')
      Sleep(3000)
      Send('Y')
      Send('{Enter}')
      Sleep(3000)
      Send('{F9}')
      Sleep(3000)
      Send('EXIT')