iwak Posted November 21, 2014 Share Posted November 21, 2014 (edited) 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: But i need to do click in here (in the center of element): Can I click on the element (with offset)? Something like this: $element.click().offset('top: 32, left: 32') ? Edited November 21, 2014 by iwak Link to comment Share on other sites More sharing options...
elmoi0010 Posted November 21, 2014 Share Posted November 21, 2014 You tryed pixelsearch? iwak 1 Link to comment Share on other sites More sharing options...
DaleHohm Posted November 21, 2014 Share Posted November 21, 2014 See _IEPropertyGet and it's example. Use it to position the mouse pointer and then click with MouseClick Dale iwak 1 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 More sharing options...
Moderators Solution SmOke_N Posted November 21, 2014 Moderators Solution Share Posted November 21, 2014 (edited) Do what Dale said, or maybe try this... I think this may work, but it's not well tested. expandcollapse popup#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 November 21, 2014 by SmOke_N iwak and DaleHohm 2 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now