Jump to content
Sign in to follow this  
JonnyF

Get link title/hint at mouse position in IE

Recommended Posts

JonnyF

Hi.

Here´s a tricky one ;)

I need to get the link title/hint that displays for the mouse position.

Say my mouse is positioned on 400x150 in IE, there is a hyperlink exactly there and therefore IE displays a yellow box with the link title in it.

I need the information in the yellow box.

Have read through the forum posts and also ie.au3 but havent found any hints.

Thanks in advance...

autoit.jpg

 

Share this post


Link to post
Share on other sites
Danp2

You can get the element below the mouse cursor with the following code:

$evt = $oIE.document.createEventObject()

$oElement = $oIE.document.elementFromPoint($evt.clientX, $evt.clientY)

If IsObj($oElement) Then
   ; Your custom code here
EndIf

From there, your should be able to use something like $oElement.Title or $oElement.Parent.Title in order to access the desired information.

Share this post


Link to post
Share on other sites
mikell

An other way ...

#include <IE.au3> 

$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.navigate("http://www.autoitscript.com/forum/")
While $oIE.Busy
    Sleep(10)
Wend

$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    ObjEvent($oLink, "_Evt_")
Next

While 1
  Sleep(10)
WEnd

Func _Evt_onMouseover()
    Local $o_link = @COM_EventObj
   $cursor = MouseGetCursor()
   If $cursor = 16 Then MsgBox(4096, "",  $o_link.title)
EndFunc

Share this post


Link to post
Share on other sites
big_daddy

I improved mikell's example.

#include <IE.au3>

$sURL = "http://www.autoitscript.com/forum/"
$oIE = _IECreate($sURL)
$HWND = _IEPropertyGet($oIE, "hwnd")
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    ObjEvent($oLink, "_Evt_")
Next
ConsoleWrite("Done adding object events." & @CRLF)

While WinExists($HWND)
    Sleep(10)
WEnd

Func _Evt_onMouseover()
    Local $o_link = @COM_EventObj
    If IsString($o_link.title) Then ConsoleWrite($o_link.title & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites
JonnyF

Thanks, it seems to work ok with some pages and some pages not at all.

If i for exaple browse to google, it will only display 0.

Havent tried the first example since i dont understand that at all.

Share this post


Link to post
Share on other sites
JonnyF

Sorry, still dont get it.

As far as i can see, no data is put into a variable or echoed.

What is the "your custom code here"?

Share this post


Link to post
Share on other sites
Danp2

Sorry, still dont get it.

As far as i can see, no data is put into a variable or echoed.

What is the "your custom code here"?

 

From there, your should be able to use something like $oElement.Title or $oElement.Parent.Title in order to access the desired information.

 

Essentially what I stated above. At that point, you have a reference to the element that was beneath the mouse cursor at the time that the hotkey was pressed. You can execute a command such as:

$itemText = $oElement.Title

or

$itemText = $oElement.Parent.Title

depending on your target on the web page.

Share this post


Link to post
Share on other sites
JonnyF

Ok, so i did this but still no luck.

#include <IE.au3> 
HotKeySet("{F2}", "getlink")

$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.navigate("http://www.google.se")

While $oIE.Busy
    Sleep(10)
Wend

While 1
    Sleep(100)
WEnd

Func getlink()
$evt = $oIE.document.createEventObject() 
$oElement = $oIE.document.elementFromPoint($evt.clientX, $evt.clientY) 

    If IsObj($oElement) Then    
        $itemText = $oElement.Parent.Title
        MsgBox(4096, "",  $itemText)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
Danp2

You said "no luck", but you didn't say what the results were or if it even ran successfully. When I attempted it with your code, it errored out on the $oElement.Parent.Title line, because the Parent element doesn't have a Title property.

I've shown you how to get the object reference to the element below the mouse pointer. You will need to "play around" to determine the exact code necessary to retrieve the desired information.

Hint: For the Google site you referenced, the following should work:

$itemText = $oElement.innerText

Share this post


Link to post
Share on other sites
mikell

God helps those who help themselves :)

Share this post


Link to post
Share on other sites
JonnyF

I am abandoning this shit and posting on rentacoder instead.

I did just humbly ask for some help, did not force anyone to answer or even read the post.

Go and bully someone else fuckfaces!

Share this post


Link to post
Share on other sites
DW1

I am abandoning this shit and posting on rentacoder instead.

I did just humbly ask for some help, did not force anyone to answer or even read the post.

Go and bully someone else fuckfaces!

What in the world happened here?  You were getting help, why are you mad?

Share this post


Link to post
Share on other sites
Jos

I am abandoning this shit and posting on rentacoder instead.

I did just humbly ask for some help, did not force anyone to answer or even read the post.

Go and bully someone else fuckfaces!

 

it's indeed better you move on and get help else were... either programming or psychiatrist

*Click*


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.