Jump to content

[IE] Clicking on element (with offset)


iwak
 Share

Go to solution Solved by SmOke_N,

Recommended Posts

Hello. Please help in the implementation of the following problem.
Need to perform a click on a particular element, but with an offset.

If i use this code:
 

$elements = _IETagNameGetCollection($oIE, "element")
For $element In $elements
If IsObj($element)
$element.click(); or _IEAction($element, "click")
EndIf
Next

Then click occurs in the upper left corner of the element:

fab91437c960.png

But i need to do click in here (in the center of element):

db5616a6273b.png


Can I click on the element (with offset)?

Something like this:
 

$element.click().offset('top: 32, left: 32')

?

Edited by iwak
Link to comment
Share on other sites

See _IEPropertyGet and it's example.  Use it to position the mouse pointer and then click with MouseClick

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • Moderators
  • Solution

Do what Dale said, or maybe try this... I think this may work, but it's not well tested.

#include <IE.au3>

Global $go_IE = _IEAttach("https://www.google.com/?gws_rd=ssl", "url")
Global $go_GB70 = _IEGetObjById($go_IE, "gb_70")

; be sure to load your window before running, maybe winactivate or something
_IE_ClickElemObjByXY($go_GB70)

Func _IE_ClickElemObjByXY(ByRef $o_obj, $n_x = Default, $n_y = Default)

    If Not IsObj($o_obj) Then
        Return SetError(1, 0, 0)
    EndIf

    #cs ; saved for later
    Local $o_bodyrect = Execute("$o_obj.document.body.getBoundingClientRect()")
    If Not IsObj($o_bodyrect) Then
        Return SetError(2, 0, 0)
    EndIf

    Local $a_bodyrect[4] = [ _
        Number($o_bodyrect.left), _ ; xpos
        Number($o_bodyrect.top), _ ; ypos
        Number($o_bodyrect.right) - Number($o_bodyrect.left), _ ; width
        Number($o_bodyrect.bottom) - Number($o_bodyrect.top)] ; height
    #ce ; saved for later

    Local $o_elemrect = Execute("$o_obj.getBoundingClientRect()")
    If Not IsObj($o_elemrect) Then
        Return SetError(3, 0, 0)
    EndIf

    Local $a_elemrect[4] = [ _
        Number($o_elemrect.left), _ ; xpos
        Number($o_elemrect.top), _ ; ypos
        Number($o_elemrect.right) - Number($o_elemrect.left), _ ; width
        Number($o_elemrect.bottom) - Number($o_elemrect.top)] ; height

    ; we'll make default center
    $n_x = ($n_x = Default) ? $a_elemrect[0] + Int($a_elemrect[2] / 2) : $n_x + $a_elemrect[0]
    $n_y = ($n_y = Default) ? $a_elemrect[1] + Int($a_elemrect[3] / 2) : $n_y + $a_elemrect[1]

    ; I'll leave error checking here for others
    Execute("$o_obj.document.elementFromPoint($n_x, $n_y).click()")
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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