Jump to content

Recommended Posts

Hi Guys,

As I am still finding my feet with AutoIT, I thought that I would do a quick test.

I therefore created some HTML code to create a small yellow non-functioning test button on a web page.

<td><div class="wg-button"><a style="position:relative" href="javascript:void(1)"><img src="button.png" alt="">
<span style="position:absolute;left:17px;top:31px; cursor:pointer; width:126px;">TEST</span></a></div></td>

I then tried to see if AutoIT could detect if I clicked on the button link.

#include <Misc.au3>
#include <Msgboxconstants.au3>

LOCAL $sColor
LOCAL $sYellow = "#FFFF00"

While 1
$sPos = MouseGetPos()
$sColor = Hex(PixelGetColor($sPos[0], $sPos[1]))
$sColor = "#" & StringMid($sColor,3)

If (_IsPressed("01") = True) And ($sColor = $sYellow) Then 
MsgBox (262144,"Found it","X=" & $sPos[0] & " Y=" & $sPos[1])


The code correctly detects when I click on the button.

However, it also highlights on anything else yellow (e.g. a yellow background) that I click on, not just the button.

I did change the link from "empty" to "www.google.com" and then checked if the current browser URL changed also, thereby indicating that I clicked on a yellow link rather than just a yellow background. That worked fine.

However, as it is about improving my knowledge of AutoIT rather than for a specific project, can anyone think of another way which I could do it?

Detecting a URL change is fine, but I then end up on a new page i.e. www.google.com.

I would like to see if I can do it without changing the size.

Any ideas?

Many thanks,



Link to post
Share on other sites

There are many ways to skin a cat :)

You could set up an event that fires before you navigate to a new page in IE using the IE UDF. There's an example of this in the help file under ObjEvent

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.


My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

This is what I've used in the past to detect the element below the mouse cursor whenever a hotkey is pressed --

Func _IEGetMouseElement($oIE, $aPoint = MouseGetPos())

    Local $hWindow = _IEPropertyGet($oIE, "hwnd")
    Local $aIEPos = _ScreenToClient($hWindow, $aPoint[0], $aPoint[1])

    Local $nScreenY = _IEPropertyGet($oIE, "screeny")
    Local $nScreenTop = $oIE.document.parentWindow.screenTop

    ; Adjust Y value for height of Tabs, Toolbars, etc
    $aIEPos[1] -= ($nScreenTop - $nScreenY)

    $oElement = $oIE.document.elementFromPoint($aIEPos[0], $aIEPos[1])

    Return $oElement

Maybe you can find a way to use it in this scenario.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By vargheseg
      I am new to AutoIT but I do use Sikuli.  Decided to use AutoIT for  this project as all  the required can be created in an .exe file, does not  need Java like Sikuli.
      Also  which can be pushed to tool bar of Windows 10 desktop.
      Our users will interact with a client/server application and normally work on dual screen. The script needs to detect the c/s application from the dual screen,  needs to do three mouse clicks based of image/pixel comparison, will need to wait till the  click object is available and then finally take screen capture  of the top 40 rows  and save the .jpeg file to  windows file share location.
      once the file save is completed,  pop up message - the screen capture is completed. Then the users can do their regular work.
      Potentially  other factor that will play are the screen resolution.
      Can anyone guide me to some relevant scripts already in the forum. In the meantime I am learning  the basics of the  tool.
      Appreciate feedback and any help
      George V
    • By nooneclose
      Good morning, I have been thinking about trying to make my Autoit script run in the background. I found out today that it is impossible due to the UIA and mouseclick functions that I use. However, while reading other posts about running Autoit scripts in the background I saw a reply mentioning how a script like mine might be able to run on a VM while still giving me the ability to work on my Host OS. Can someone confirm this? 
      Here is a link to the thread where I saw VM mentioned. 
      the person who mentioned it was @ViciousXUSMC 
    • By jparnell8839
      I'm hoping this is feasible... I made a program that resides in the system tray. One of the tray items runs a function that waits for the user to click on a window to get the window title.
      I would like for the mouse cursor to change to the cross while waiting for user input. I have tried using GUISetCursor(3), but from my understanding this only changes the cursor for an AutoIt GUI window.
      How could I go about changing the mouse cursor for the user's environment, not just for the AutoIt window?
    • By irfan666
      Hi, how to make autoit "monitoring" program, Basically i want autoit to autoclick "start" button only  when the program is "stop" ? thanks

    • By jlorenz1
      PixelSearch ( left, top, right, bottom, color [, shade-variation = 0 [, step = 1 [, hwnd]]] )
      Searches a rectangle of pixels for the pixel color provided  depending on a specified window handle.

      MouseClick ( "button" [, x, y [, clicks = 1 [, speed = 10]]] ) makes a click on a specified position.
      How can I simulate a MouseClick on a window depending on a specified handle, which is invisibel, and without moving the mouse really?
      Is this possible? How is the syntax?
      Thanks in advance
  • Create New...