Jump to content

Detecting a click on an empty link


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 $sPos
LOCAL $sColor
LOCAL $sYellow = "#FFFF00"

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

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

Wend

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,

Pete 

 

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

Spoiler

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
InputBoxes - Simple Input boxes for various variable types

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

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

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

×
×
  • Create New...