How to locate a button on a web page pop-up (Version 1.1.33.09)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rllets
Posts: 2
Joined: 21 Jun 2021, 00:55

How to locate a button on a web page pop-up (Version 1.1.33.09)

24 Jun 2021, 12:24

I work on Ancestry.com daily building family trees. The most common action is to open a person's profile from his/her node in the tree. It's a right click on person, wait for pop-up, left click on button in the pop-up, wait for list, right click on 1st entry in the list. I do this action dozens of time each session. Fingers and brain get wonkey after a couple dozen times, do the wrong click, miss the timing, and generally wear out. I discovered AutoHotkey a few days ago. Looks like a solution to this and many other repetitious actions I do.

After a lot of study and experimenting, I got 2 hotkey scripts going, the first got to the pop-up and the second one started at the left click and finished the job. However, I couldn't find an AutoHotkey way to get the mouse cursor over to the pop-up button. Focus was on the pop-up key I needed to push and I could Send, {ENTER} but that brought the profile up in place of the tree. I needed to do a right click to get the context menu so the profile would come up in a new tab.

I should mention that the pop-up comes up near the tree node clicked, that is, any where in the tree window. The pop-up's size is unpredictable as is the button location within the pop-up. A varying number of lines of text appear in the pop-up above the button and other information can be placed below the button in the pop-up. So, even if I could get the coordinates of the pop-up, I still wouldn't know where the button is horizontally.

Using the 2 hotkey scripts was an improvement on the manual method. Then I thought of a way to combine them. I put them together with a Sleep 2000 in between. This gave me enough time to slide the mouse over to the button manually and a one hotkey action. Even more improvement.

Code: Select all

MButton::
Click Left
Sleep 2000
Click Right
Send, {DOWN  1}
Send, {ENTER}
return
Further reading on the web led to discovery of ImageSearch. I clipped a portion of the button label and with a lot of fine tuning of color shade level, ImageSearch could find the button. This finally gave the button coordinates needed to make the hotkey fully automatic.

Code: Select all

MButton::
Click Left
sleep 500
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 C:\Users\...
if (ErrorLevel = 2)
    MsgBox Could not conduct the search.
else if (ErrorLevel = 1)
    MsgBox Icon could not be found on the screen.
Click, %FoundX% %FoundY%, Right
Send, {DOWN  1}
Send, {ENTER}
Send, {ESC}
return
This being my first attempt at an AutoHotkey script, I expect it's highly likely that I missed some better techniques and that there may be some pitfalls of the method I've used. Is this a reasonable solution? Are there better ways to do this?
Last edited by gregster on 25 Jun 2021, 03:02, edited 2 times in total.
Reason: Topic moved from ' AutoHotkey v2 Help'.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: How to locate a button on a web page pop-up (Version 1.1.33.09)

24 Jun 2021, 20:22

If you’re working within a browser window, and the pop-up is produced by the webpage, then it typically wouldn’t be seen as a separate window and wouldn’t have addressable controls. If that’s he case, then I’d say using ImageSearch is a reasonable approach.

You can see what the Window Spy tool that comes with AHK shows regarding the pop-up. If it actually has different window title information than your main working window and especially if the button you want to click has its own “ClassNN,” then you could try using ControlClick to click that button. If not, you’re probably about as good as you’re going to get with what you have already.

There might be possibilities using various browser automation tools or libraries that are written in or work with AHK. Microsoft Active Accessibility (MSAA) is another approach for which there is AHK support. I would stick with what you have as long as it’s working well enough before going down either of those paths, though.
rllets
Posts: 2
Joined: 21 Jun 2021, 00:55

Re: How to locate a button on a web page pop-up (Version 1.1.33.09)

25 Jun 2021, 10:41

boiler - thank you for your response. I appreciate your comments on this. It's good to know that I didn't miss something simpler. Knowing there isn't something better is just as good as finding out there is something better.

I forgot to mention that I did scan the web page with Window Spy and, just as you say, it did not see the pop-up as a different window. Everything in the Window section and the Control Under Mouse Position section stayed the same all over the page and the pop-up.

I did try Click Right to see if the cursor was on the button per chance but it was not. Focus was there but not the mouse cursor.

I'm using the Brave browser, built on Chrome, and I see Chrome has an add-on for AHK. I might try that some day but for now, I'm following your suggestion to use what I've got since it meets all my criteria - works, one-click, one hand.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 340 guests