IE COM fire click event

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

IE COM fire click event

04 Dec 2018, 09:25

I got stuck on this one. It seems like the event should be mouseclick, but neither mouseclick or any other event works to click that button.
clicknotfound.png
clicknotfound.png (15.11 KiB) Viewed 6473 times
maybe someone have some ideas why none of the events works?
I have tried those event and all other Jethrow have made:

Code: Select all

MouseClick  := pwb.document.createEvent("MouseEvent")  ;Mouse Click
MouseClick.initMouseEvent("click",true,false,,,,,,,,,,,,,0) ;Initialize Event
pwb.document.getElementsByClassName("avoidbeforeload")[13].click()
pwb.document.getElementsByClassName("avoidbeforeload")[13].dispatchEvent(MouseClick)

Code: Select all

pwb.document.getElementsByClassName("avoidbeforeload")[13].fireEvent("onclick")
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: IE COM fire click event

04 Dec 2018, 20:35

I would think this would work:

Code: Select all

pwb.document.getElementsByClassName("avoidbeforeload")[13].click()
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IE COM fire click event

05 Dec 2018, 02:28

that's like the first method every developer would do. Offcourse I have tried it and it doesn't work. If I click that button with mouse - then it works.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: IE COM fire click event

05 Dec 2018, 18:33

Can’t help ya then
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: IE COM fire click event

05 Dec 2018, 18:41

Sometimes click() works when applied to an ancestor or descendant element.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: IE COM fire click event

05 Dec 2018, 19:57

@euras, would you mind trying this mini-mod to kczx3's code? I don't have any way to test it, and I have little experience with this so far.

Code: Select all

pwb.document.getElementsByClassName("avoidbeforeload").submit.click()
The reason I'm asking this is because, while going through Jethrow's tutorial, I discovered a few errors (which may not have been errors when they were written).
In one of the first tutorial code segments here the code given is:

Code: Select all

javascript: document.all.submit.click()
wb.document.submit.click()
which obviously isn't going to work. It has to be

Code: Select all

javascript: document.all.submit.click()
wb.document.all.submit.click()
this (tested).

(As directed I used the archived "Search Forum" page here.)

Another code segment on the same tutorial page is this:

Code: Select all

javascript: document.all.search_content.selectedIndex = 1;  void 0 // .value = 'titles'
wb.document.all.search_content.selectedIndex = 1  ;// .value := "titles"
which throws an error.

Experimenting a little, trying to use something similar to what you're doing, I found another way to click the "Search Now" button was this:

Code: Select all

wb.document.getElementsByClassName("input_submit").submit.click()
That's what made me suggest the snippet above. I realize there's no index in my snippets. Maybe you have to have it, I don't have any way to check. Sorry for wasting your time if this is a red herring.

Regards,
burque505
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: IE COM fire click event

07 Dec 2018, 05:20

Some examples of sending click:

Code: Select all

oIE := ComObjCreate("InternetExplorer.Application")
oIE.navigate("http://help.dottoro.com/external/examples/ljwcseaq/onmousedown_4.htm")
oIE.visible := True, oIEHWND := oIE.HWND
WinMaximize ahk_id %oIEHWND%
While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10

;~ initMouseEvent(eventType, canBubble, cancelable, viewArg, detailArg, screenXArg, screenYArg, clientXArg, clientYArg, ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg, buttonArg, relatedTargetArg)

MouseDownEvent := oIE.document.createEvent("MouseEvent")
MouseDownEvent.initMouseEvent("mousedown",true,false, _, _, _, _, _, _, _, _, _, _, _, _)

MouseUpEvent := oIE.document.createEvent("MouseEvent")
MouseUpEvent.initMouseEvent("mouseup",true,false, _, _, _, _, _, _, _, _, _, _, _, _)


oIE.document.querySelector("BUTTON[Id=""testButton""]").dispatchEvent(MouseDownEvent)
oIE.document.querySelector("BUTTON[Id=""testButton""]").dispatchEvent(MouseUpEvent)

return

Code: Select all

IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
 
oIE := ComObjCreate("InternetExplorer.Application")
oIE.navigate("http://help.dottoro.com/external/examples/ljwcseaq/onmousedown_4.htm")
oIE.visible := True, oIEHWND := oIE.HWND
WinMaximize ahk_id %oIEHWND%
While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10
 
window := ComObj(9,ComObjQuery(oIE,IID,IID),1)
 
window.OnButtonDown(button := oIE.document.getElementById("testButton"))
sleep 200
window.OnButtonUp()

Code: Select all

oIE := ComObjCreate("InternetExplorer.Application")
oIE.navigate("http://help.dottoro.com/external/examples/ljwcseaq/onmousedown_4.htm")
oIE.visible := true

While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10

oIE.document.parentWindow.execScript("OnButtonUp()")
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: IE COM fire click event

07 Dec 2018, 08:54

- @malcev: What is the value of _ supposed to be, is a blank string OK?
- Do you have any ideas for this script? E.g. to send a click or enter key. I used ControlSend for it. Thanks.
script to full screen YouTube videos - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=34868
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: IE COM fire click event

07 Dec 2018, 09:01

@malcev, thank you for the helpful code, and for the link to Dottoro.
Regards,
burque505
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: IE COM fire click event

08 Dec 2018, 12:50

jeeswg wrote:
07 Dec 2018, 08:54
- @malcev: What is the value of _ supposed to be, is a blank string OK?
Yes.
About youtube.
I cannot send "enter" to buttons like this:

Code: Select all

input := oIE.document.querySelector(".ytp-fullscreen-button.ytp-button")
event := oIE.document.createEvent("Event")
event.initEvent("keydown", true, true)
event.keyCode := 13 ; enter
msgbox % input.dispatchEvent(event)
nor like this:

Code: Select all

input := oIE.document.querySelector(".ytp-fullscreen-button.ytp-button")
event := oIE.document.createEvent("KeyboardEvent")
event.initKeyboardEvent("keydown", true, true, oIE.document.defaultView, "Enter", 0, "", false, "en-US")
input.dispatchEvent(event)
Also double click i can send only when video is fullscreen:

Code: Select all

doubleClickEvent := oIE.document.createEvent("MouseEvents")
doubleClickEvent.initEvent("dblclick", true, true)
oIE.document.querySelector(".video-stream.html5-main-video").dispatchEvent(doubleClickEvent)
May be there is some javascript protection...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: IE COM fire click event

08 Dec 2018, 14:08

- @malcev: Many thanks for your efforts, much appreciated.
- Btw other browsers support 'f', so perhaps 'f' is worth trying.
- Interestingly, I've found that this can be done via Acc.

Code: Select all

q:: ;internet explorer - youtube - full screen
WinGet, hWnd, ID, A
;note: the Acc path can change
;oAcc := Acc_Get("Object", "4.6.4.2.4.1.4.1.1.15.3.1.46", 0, "ahk_id " hWnd)
oAcc := Acc_Get("Object", "4.6.4.2.4.1.4.1.1.15.3.1.44", 0, "ahk_id " hWnd)
if (oAcc.accName(0) = "Full screen")
	oAcc.accDoDefaultAction(0)
oAcc := ""
return

:w:: ;anywhere - get text and acc paths for gui elements
WinGet, hWnd, ID, A
Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: IE COM fire click event

10 Dec 2018, 06:42

I think that it is restriction policies of IE.
Because if we use iMacros, then the code will work with other browsers except IE.
But with selenium click works because:
As the InternetExplorerDriver is Windows-only, it attempts to use so-called "native", or OS-level events to perform mouse and keyboard operations in the browser.
https://github.com/SeleniumHQ/selenium/ ... orerDriver

euras, If You want to understand what You have to send to click this button, You have to:
1) Open chrome developer tool.
2) Select element that You want monitor.
3) Open console window and execute to monitor all events with this element:

Code: Select all

monitorEvents($0)
https://developers.google.com/web/tools ... ole/events
4) Repeat some of this events in IE.
For example:
If we run this code, then if we press "sign in" it shows error:

Code: Select all

oIE := ComObjCreate("InternetExplorer.Application")
oIE.Visible := True
oIE.Navigate("https://www.artstation.com/registration/signup")
While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10

target := oIE.document.querySelector("input[name=""first_name""]")
target.value := "tester"
If we examine events of this link in Chrome, then we will get this code, that will work:

Code: Select all

oIE := ComObjCreate("InternetExplorer.Application")
oIE.Visible := True
oIE.Navigate("https://www.artstation.com/registration/signup")
While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10

target := oIE.document.querySelector("input[name=""first_name""]")
target.value := "tester"
event := oIE.document.createEvent("Event")
event.initEvent("input", true, true)
target.dispatchEvent(event)
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IE COM fire click event

14 Dec 2018, 07:01

sadly the problem was still not solved.. :/
What events I see on that element:
onclick.PNG
onclick.PNG (9.4 KiB) Viewed 6207 times
it's also javascript:

Code: Select all

javascript:void(0)

Code: Select all

pwb.document.getElementById("1_ReportViewer1_ctl06_ctl04_ctl00_Menu").getElementsByClassName("avoidbeforeload")[4].click() ; doesn't work

Focus := pwb.document.createEvent("FocusEvent")  ; doesn't work
Focus.initEvent("focus", true, true) ;Initialize Event
pwb.document.getElementById("1_ReportViewer1_ctl06_ctl04_ctl00_Menu").getElementsByClassName("avoidbeforeload")[4].fireEvent("onclick")
pwb.document.getElementById("1_ReportViewer1_ctl06_ctl04_ctl00_Menu").getElementsByClassName("avoidbeforeload")[4].dispatchEvent(Focus)

MouseOver  := pwb.document.createEvent("MouseEvent")  ; doesn't work
MouseOver.initMouseEvent("mouseover",true,false,,,,,,,,,,,,,0) ;Initialize Event
pwb.document.getElementById("1_ReportViewer1_ctl06_ctl04_ctl00_Menu").getElementsByClassName("avoidbeforeload")[4].fireEvent("onclick")
pwb.document.getElementById("1_ReportViewer1_ctl06_ctl04_ctl00_Menu").getElementsByClassName("avoidbeforeload")[4].fireEvent("onclick")dispatchEvent(MouseOver)
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: IE COM fire click event

14 Dec 2018, 07:40

FireEvent does not work with ie11.
You have to monitor events in console.
It doesn't make sense to discuss about this without Your link.
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IE COM fire click event

20 Dec 2018, 02:34

I can't share the link, because it's work environment. The HTML code of the element is:

Code: Select all

<a class="avoidbeforeload" style="padding: 3px 8px 3px 32px; color: rgb(51, 102, 204); font-family: Verdana; font-size: 8pt; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('1_ReportViewer1').exportReport('EXCELOPENXML');" href="javascript:void(0)">Excel</a>
while I'm trying to see properties of that link which I want to click, I see only

Code: Select all

javascript:void(0)
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: IE COM fire click event

12 Feb 2019, 09:35

@euras,

Did you ever find a solution? I'm trying to automate the report viewer in my work environment also.

I want to script exporting a SQL report to Excel automatically.

Code: Select all

<a title="Excel" alt="Excel" onclick="$find('ReportViewer1').exportReport('EXCELOPENXML');" href="javascript:void(0)" style="color: rgb(51, 102, 204); font-family: Verdana; font-size: 8pt; padding: 3px 8px 3px 32px; display: block; white-space: nowrap; text-decoration: none;">Excel</a>
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: IE COM fire click event

12 Feb 2019, 10:16

You just need to select that link and call onclick()

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], makdc96, RandomBoy, Rohwedder and 174 guests