How to Click a Button in a Web Page?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Era
Posts: 26
Joined: 28 Apr 2018, 22:36

How to Click a Button in a Web Page?

17 Jun 2018, 14:32

I'd like to simulate a mouse-click on this button. How can that be done? Here's the Chrome HTML for the button:

Code: Select all

<button class="btn btn-success" ng-click="$ctrl.submit()" ng-disabled="!$ctrl.canSubmitReply()">

<!----><span translate="DISCUSSION_SUBMIT_REPLY" ng-if="!item" ng-show="!submitting" aria-hidden="false" class="">Submit</span><!----> <!----> <span class="icon icon-circle-right" ng-show="!submitting" aria-hidden="false"></span> 

<span translate="DISCUSSION_SUBMITTING_REPLY" ng-show="submitting" aria-hidden="true" class="ng-hide">Submitting</span> <span class="icon de-spin icon-spinner-dots ng-hide" ng-show="submitting" aria-hidden="true"></span></button>
Thank you.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to Click a Button in a Web Page?

17 Jun 2018, 19:14

- Here's the sort of investigation/experimentation I do, to identify the right web element in Internet Explorer:

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

;note: getElementsByClassName/getElementsByTagName methods [elements plural]:
;you can loop through elements with a particular class/tag, and check info on them to find the right one,
;or get the nth element (0-based index) with a particular class/name if the index is consistent

;note: getElementById method [element singular]:
;you can get direct access to an element if it has a unique ID

;note: getElementXXX methods
;you can find an element via a getElementXXX method,
;and then search through its elements by using a getElementXXX method,
;i.e. find an easily identifiable element to narrow down the search

;note: parentElement and childNodes properties
;these can be used to navigate to/query parent/child elements

;note: getAttribute
;this can be used to retrieve an element's attribute or a blank string, without crashing AHK,
;alternatively you can use try and catch

q:: ;Internet Explorer - click button
WinGet, hWnd, ID, ahk_class IEFrame
oWB := WBGet("ahk_id " hWnd)
vEltClass := "btn btn-success"
MsgBox, % oWB.document.getElementsByClassName(vEltClass).length
oElt := oWB.document.getElementsByClassName(vEltClass)[0]
MsgBox, % oElt.innerText
MsgBox, % oElt.outerHTML
oElt.click()
oWB := ""
return
- Similar logic may be applicable to other web browsers.
- To automate Firefox/Chrome you could consider:
[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=42890
Using Selenium with AutoHotkey- Cross browser automation! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=32323
- Use iWB2 Learner to investigate IE tabs (zoom must be set to 100% for the box outlines to align correctly). Download here:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
- There is some other similar information here:
Help with ControlSend (or Control) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=50499
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Era
Posts: 26
Joined: 28 Apr 2018, 22:36

Re: How to Click a Button in a Web Page?

17 Jun 2018, 22:24

Thank you! I'll experiment with these...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 277 guests