How to click a button on a web page (tabbing doesn't work)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 539
Joined: 22 Oct 2015, 17:56

How to click a button on a web page (tabbing doesn't work)

Post by omar » 23 Sep 2021, 09:35

I want to click a button on a web page.
I can't seem to get to it by tabbing.

I'm sure I can identify the button HTML code... but then how do I invoke the clicking?

Thanks.

alancantor
Posts: 76
Joined: 11 Jun 2019, 11:28

Re: How to click a button on a web page (tabbing doesn't work)

Post by alancantor » 23 Sep 2021, 20:39

A quick-and-dirty solution: search for text that's near the button you want to click on. Then Tab (or Shift+Tab) to the intended target. Press spacebar to activate it. Or if it's a link styled to look like a button, activate with Enter.

In pseudo code:

Press Esc // Cancel previous search, if there is one.
Press Ctrl + F // Invoke Find
Press Contact // ...or whatever unique text is searchable and conveniently close to your target
Press Esc // Cancel Find, which leaves keyboard focus on the text you've searched for
Press Tab Tab // In this case, press Tab twice to reach the target
Press spacebar // ...or Enter, if it's hypertext and not a button

You'll likely need to insert short pauses between some steps.

I find solutions like this can be made to work, and near perfect reliability is achievable. But it's an inherently flaky way to automate webpage navigation.

Jakson
Posts: 47
Joined: 25 Jun 2021, 15:19

Re: How to click a button on a web page (tabbing doesn't work)

Post by Jakson » 24 Sep 2021, 16:24

If you're never going to resize the window and it always appears in the exact same dimensions just get a measurement for where the button is and do a coordinated Click with coordinate values.

The big problem with this method is that if anything changes, the button on the page, the size of the window, the position of the window, the size or resolution of the monitors, the code will click where the button WAS.

Alternatively, if the button is colored uniquely from objects surrounding it you could do a PixelSearch [ PixelSearch help ] for the specific color. Once the color is found you can take the coordinates for the found pixel and turn them into Click coordinates or MouseMove coords.

The PixelSearch method is prone to some of the same flaws as the first method I mentioned, just telling AHK where the thing is by coordinates. You need to prime your PixelSearch with an area to search. If your window changes dimensions or the button changes location you're probably not going to be able to find the button again this way.

Post Reply

Return to “Ask for Help (v1)”