Basic UIA tasks
Re: Basic UIA tasks
@LAPIII, xccEl.WaitElement({Type:"TabItem", Name:"On Xbox Live"}).Click() ;isn't working when nothing in it I have no idea what you mean by "isn't working", because I don't have Xbox Live to test it. If the element might not exist at all, then you shouldn't use WaitElement without a timeout value, otherwise it'll wait indefinitely.
Your "d" hotkey is again mixing v1 and v2 code. There is no FindFirstBy in UIA v2 for starters...
Your "d" hotkey is again mixing v1 and v2 code. There is no FindFirstBy in UIA v2 for starters...
Re: Basic UIA tasks
Can I possibly make this activate only on in the Captures window. At the top of the window is the word Captures (Type: "Text ", Name:"Captures" ):
Code: Select all
#HotIf WinActive("Xbox Console Companion ahk_exe ApplicationFrameHost.exe")
d::xccEl.WaitElement({Type:"Button", Name:"Delete"}).Click()
Re: Basic UIA tasks
@Descolada I think that the shortcut in the post above can use an If I just don't know how to write it. Could you help me please?
Re: Basic UIA tasks
@LAPIII, #HotIf should be used with functions that have a fast execution time (otherwise the key would be too laggy), and I don't think UIA is fast enough for this. You can try it out of course, something like
But I think this would make the "d" key slow to respond, so I think I'd use a hotkey with a modifier (which hopefully doesn't already have an action tied to it):
Code: Select all
#HotIf WinActive("Xbox Console Companion ahk_exe ApplicationFrameHost.exe") && UIA.ElementFromHandle("Xbox Console Companion ahk_exe ApplicationFrameHost.exe").ElementExist({Type:"Text", Name:"Captures"})
d::xccEl.WaitElement({Type:"Button", Name:"Delete"}).Click()
Code: Select all
#HotIf WinActive("Xbox Console Companion ahk_exe ApplicationFrameHost.exe")
+d:: ; Shift+d
{
if UIA.ElementFromHandle("Xbox Console Companion ahk_exe ApplicationFrameHost.exe").ElementExist({Type:"Text", Name:"Captures"})
xccEl.WaitElement({Type:"Button", Name:"Delete"}).Click()
}
Re: Basic UIA tasks
I can't get the hotkey to work:
Code: Select all
if not A_IsAdmin
Run("*RunAs `"" A_ScriptFullPath "`" /restart")
If WinExist("ahk_exe Brother iPrintScan.exe"){
WinActivate()
}Else
{
run("C:\Program Files (x86)\Brother\iPrint&Scan\Brother iPrint&Scan.exe")
}
Sleep(3000)
iPSEl := UIA.ElementFromHandle("ahk_exe Brother iPrint&Scan.exe")
#HotIf WinActive("ahk_exe Brother iPrint&Scan.exe")
s::iPSEl.WaitElement({Type:"Button", Name:"Scan"}).Click()
Re: Basic UIA tasks
@LAPIII, "I can't get the hotkey to work" is not a helpful statement to get you a solution. You need to do some debugging to understand whether it's the WinActive("ahk_exe Brother iPrint&Scan.exe") statement that isn't correct (perhaps the exe name is incorrect), or the element isn't being found, or something else entirely. If this is about getting a hotkey to trigger properly, then your problem isn't with UIA and you should create a new thread for that.
Re: Basic UIA tasks
Can you use If and else? Please give me an example. I found the following lines of code in an example and thought that this would be more useful:
EDIT: is it faster using ElementFromPath() than FindElement()?
Code: Select all
if cUIA.ElementFromPath("Y/YYY/YqYYYYVRRRqRyIJ").Click() ; Not part of this demonstration
try explorerEl.FindElement({T:0,N:"Minimize the Ribbon"}).Invoke() ; Not part of this demonstration
Re: Basic UIA tasks
@LAPIII, you can use if/else, but only whether an element was found or not, and in that case you would need to use the Exist variants of the methods.
One way is using try-catch:
Another way is if-else with Exist methods:
ElementFromPath is generally faster than FindElement, unless you use FindElement with TreeScope Children (which greatly limits its search scope and thus makes the search faster). Also see "Speed improvements" in the Wiki.
One way is using try-catch:
Code: Select all
try {
cUIA.ElementFromPath("Y/YYY/YqYYYYVRRRqRyIJ").Click() ; If this throws an error, then the next line won't be executed
explorerEl.FindElement({T:0,N:"Minimize the Ribbon"}).Invoke()
} catch {
MsgBox("Something went wrong")
}
Code: Select all
if button := cUIA.ElementFromPathExist("Y/YYY/YqYYYYVRRRqRyIJ")
button.Click()
else
MsgBox("The element doesn't exist, thus can't be clicked")
Re: Basic UIA tasks
I'm trying to make a script that works with Google Sheets, but my hotkey for moving to a cell doesn't work:
Here is the error that I get:
Code: Select all
#SingleInstance Force
#Requires Autohotkey v2.0+
#NoTrayIcon
#Include <UIA>
#Include <UIA_Browser>
WinWaitActive "ahk_exe msedge.exe"
cUIA := UIA_Browser()
cUIA.ElementFromHandle("ahk_exe msedge.exe")
#HotIf WinActive("Google Sheets ahk_exe msedge.exe")
q::cUIA.Move(433,125)
Re: Basic UIA tasks
@LAPIII, and what exactly should cUIA.Move(433,125) do? "Move" can either belong to TextPattern, used to manipulate selectable text, or to TransformPattern, used to move the window. It will not select a cell in Google sheets, nor can you easily select cells with UIA because Google hasn't done accessibility that well.
I'd recommend using some browser library to automate it (Chrome.ahk, Edge.ahk, Rufaydium etc), or you can record and edit macros in Google Sheets (Extensions -> Macros) where you can assign a hotkey to it (it allows only Ctrl+Alt+Shift+character hotkeys, which I guess you could also trigger from AHK with another hotkey).
I'd recommend using some browser library to automate it (Chrome.ahk, Edge.ahk, Rufaydium etc), or you can record and edit macros in Google Sheets (Extensions -> Macros) where you can assign a hotkey to it (it allows only Ctrl+Alt+Shift+character hotkeys, which I guess you could also trigger from AHK with another hotkey).
Re: Basic UIA tasks
Is it possible to use the property Name, But only with the first word or part of it?
Re: Basic UIA tasks
Yes: {Name:"somename", MatchMode:"StartsWith"} or {Name:"somename", MatchMode:"Substring"}
Re: Basic UIA tasks
Can I write to pick between two path, i.e. if one elements path doesn't exist then it chooses the second?
Re: Basic UIA tasks
You can create "or" conditions with the array notation, so [{Name:"some"}, {Name:"other"}] will match an element with name "some" or "other".
If you want to do the same with paths you need to use ElementFromPathExist and use AHK-s "or" operator: found := El.ElementFromPathExist(path1) || El.ElementFromPathExist(path2)
If you want to do the same with paths you need to use ElementFromPathExist and use AHK-s "or" operator: found := El.ElementFromPathExist(path1) || El.ElementFromPathExist(path2)
Re: Basic UIA tasks
I used: $l::cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRRqRt0") || cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRR/RzrrK0").Click()
And got: Error: This value of type "Integer" has no method named "Click".
EDIT: I started my script with the following:
And got: Error: This value of type "Integer" has no method named "Click".
EDIT: I started my script with the following:
Code: Select all
#Requires Autohotkey v2.0+
#Include <UIA>
#Include <UIA_Browser>
WinWaitActive "ahk_exe msedge.exe"
cUIA := UIA_Browser()
cUIA.ElementFromHandle("ahk_exe msedge.exe")
Re: Basic UIA tasks
You code cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRRqRt0") || cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRR/RzrrK0").Click() evaluates to either cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRRqRt0") or if no such element is found, cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRR/RzrrK0").Click(). You should use (cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRRqRt0") || cUIA.ElementFromPathExist("Y/YYY/YqYYYYYYVRRR/RzrrK0")).Click() instead.
Also, I won't answer any more of your questions in this thread. You are constantly making mistakes with basic AHK syntax and most of your problems have nothing to do with UIA. You should go back to the basics and learn AHK syntax with easier code and simpler libraries before tackling Acc or UIA any further.
Also, I won't answer any more of your questions in this thread. You are constantly making mistakes with basic AHK syntax and most of your problems have nothing to do with UIA. You should go back to the basics and learn AHK syntax with easier code and simpler libraries before tackling Acc or UIA any further.