Help close Opera using the UIA library.

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
LAPIII
Posts: 671
Joined: 01 Aug 2021, 06:01

Help close Opera using the UIA library.

Post by LAPIII » 27 Aug 2023, 12:43

I want to be able to close Opera when the last tab doesn't exist. I tried the following, which doesn't work so I need help:

Code: Select all

#Requires Autohotkey v2.0+
#Include <UIA>
cUIA := UIA.ElementFromHandle("ahk_exe opera.exe")

if (foundElement := cUIA.WaitNotExist({Type:"TabItem""}))
WinClose()
I would like to have a loop that will wait until no tab exists.

User avatar
MrDodel
Posts: 96
Joined: 28 Apr 2021, 09:03
Location: Event Horizon

Re: Help close Opera using the UIA library.

Post by MrDodel » 27 Aug 2023, 14:57

@LAPIII, you're really not helping yourself at all.

This forum isn't for people just to supply a plugin answer you can run with, that's not how it works.

It's time you started reading and understanding what is offered by the countless people who have helped you historically and reading the AutoHotkey / UIA documentation.

Sorry, but many other users post questions and take it on board, you just seem to want spoon-feeding.

Take care.

Edit: Typo.
So much universe, and so little time. GNU Sir Terry.

LAPIII
Posts: 671
Joined: 01 Aug 2021, 06:01

Re: Help close Opera using the UIA library.

Post by LAPIII » 27 Aug 2023, 18:53

I think that I've got it:

Code: Select all

#Requires Autohotkey v2.0+
#Include <UIA>
#Include <UIA Browser>
cUIA := UIA.ElementFromHandle("ahk_exe opera.exe")

q::{
Loop {
if (foundElement := cUIA.WaitNotExist({Type:"TabItem", LocalizedType:"tab item"}))
try cUIA.FindElement("Y/YYYY0/").Click()         ; Close button
}}
But I cannot test it because every time I get the following error (I hope @Descolada can help with it):

TEST_2.ahk 27_08_23 07⦂48⦂22⦂175 PM.jpg
TEST_2.ahk 27_08_23 07⦂48⦂22⦂175 PM.jpg (50.49 KiB) Viewed 362 times
Last edited by LAPIII on 04 Sep 2023, 09:22, edited 1 time in total.

LAPIII
Posts: 671
Joined: 01 Aug 2021, 06:01

Re: Help close Opera using the UIA library.

Post by LAPIII » 01 Sep 2023, 08:56

bump

Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: Help close Opera using the UIA library.

Post by Descolada » 01 Sep 2023, 09:12

The description for WaitNotExist is "Waits for this element to not exist" and the definition is WaitNotExist(timeOut:=-1). In your code {Type:"TabItem", LocalizedType:"tab item"} is obviously not a valid timeout value which is why you are getting an error. Instead you need to use WaitElementNotExist.

Post Reply

Return to “Ask for Help (v2)”