UIA2 is managed. I think You can run it with clr.
@Shield
You can look here
viewtopic.php?t=93892
Code: Select all
#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
#Include, %A_Scriptdir%\lib\UIA_Interface.ahk
#Include, %A_Scriptdir%\lib\UIA_Browser.ahk
webAutoItemInput()
return
webAutoItemInput() {
; example variable set webpage & item
webTextInfo := "https://www.js-filter.com/catalogue,17801-10030"
; analize and split string
info := StrSplit(webTextInfo, ",")
webpage := info[1], item := info[2]
; move mouse to center of screen to prevent any weird popups or change in UI
CoordMode, Mouse, Screen
MouseMove, (A_ScreenWidth // 2), (A_ScreenHeight // 2), 0
; runs chrome if not active, activates chrome if exists
browserExe := "chrome.exe"
if !WinExist("ahk_exe " browserExe)
Run, %browserExe%
else
WinActivate, % "ahk_exe " browserExe
WinWaitActive, ahk_exe %browserExe%
WinMaximize, ahk_exe %browserExe%
; create UIA instance
UIA := new UIA_Browser("ahk_exe " browserExe)
; check if UIA instance exists
if !(IsObject(UIA)) {
msgbox UIA is not loaded
return
}
; start UIA work
Try {
if !(UIA.GetCurrentURL() == "chrome://new-tab-page/") {
UIA.NewTab()
; tooltip, waiting for new tab to load
UIA.WaitPageLoad("New Tab", 1000)
; tooltip, navigating to webpage
}
UIA.Navigate(webpage)
; tooltip, waiting for webpage to load
UIA.WaitPageLoad()
if (webpage == "https://www.jnbk-brakes.com/catalogue/cars" || webpage == "https://www.js-filter.com/catalogue") {
retries := 0
checkEl:
; THIS IS THE ISSUE
; THE FindFirstBy Method is a bit slow
; I WOULD SAY IT'S AROUND 1 SEC SLOWER THAN MANUAL INPUT
; NOT SURE IF THERE IS A FASTER WAY?
editEl := UIA.FindFirstBy("AutomationId=txtPartNo")
; check if input element exists
if !(IsObject(editEl)) {
; retry if input doesn't exist
; maybe there is no internet
retries := retries + 1
if (retries > 3)
return
sleep 500
Gosub, checkEl
return
}
; Automate inputs and clicks
editEl.SetValue(item)
UIA.FindFirstBy("AutomationId=btnProductSearch").Click()
}
}
}
Code: Select all
SendMode Input
SetWorkingDir, %A_ScriptDir%
#include C:\Users\Ha Noi\Desktop\UIAutomation-main\Lib\UIA_Interface.ahk
#include C:\Users\Ha Noi\Desktop\UIAutomation-main\Lib\UIA_Constants.ahk
F3::
UIA := UIA_Interface() ; Initialize UIA interface
B1 := UIA.ElementFromHandle(WinExist("ahk_exe Nghiep vu Bao hiem.exe")) ;
Nuttim := B1.FindFirstByName("T×m")
While IsObject(Nuttim) = 0
{
Nuttim := B1.FindFirstByName("T×m")
}
Nuttim.Highlight()
Code: Select all
#Include <UIA_Interface>
#Include <UIA_Browser>
Gui, New,, MyTest
Gui, Add, Button, gTest, T×m
Gui, Show
WinWaitActive, MyTest
UIA := UIA_Interface()
wEl := UIA.ElementFromHandle("MyTest")
wEl.FindFirstByNameAndType("T×m", "Button").Click()
ExitApp
Test:
MsgBox, Test
return
Code: Select all
cUIA.WaitPageLoad("Page Name")
Code: Select all
WinGetTitle, PageTitle, A
while !instr(PageTitle,row.name)
{
sleep,500
; tooltip,% PageTitle
WinGetTitle, PageTitle, A
}
Code: Select all
cUIA := new UIA_Browser("ahk_exe " browserExe)
Code: Select all
Error in #include file "UIA_Browser.ahk":
0x80004003 - Pointer not valid.
Specifically: GetFirstChildElement (UIA_TreeWalker)
Line#
434: {
435: Try
435: {
436: if this.ReloadButton && this.ReloadButton.CurrentName
437: Return,this.ReloadButton
438: }
439: ButtonWalker := this.UIA.CreateTreeWalker(this.ButtonCondition)
---> 440: this.ReloadButton := ButtonWalker.GetNextSiblingElement(ButtonWalker.GetNextSiblingElement(ButtonWalker.GetFirstChildElement(this.NavigationBarElement)))
441: Return,this.ReloadButton
442: }
445: {
446: this.JSExecute("document.title=""" newTitle """; void(0);")
447: }
449: {
450: this.SetURL("javascript:" js, True)
The current thread will exit.
Code: Select all
#SingleInstance, force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#include <UIA_Interface>
EventHandler(el) {
ToolTip, % "Caught event!`nElement name: " el.CurrentName
}
ExitFunc() {
UIA.RemoveFocusChangedEventHandler(h) ; Remove the event handler. Alternatively use UIA.RemoveAllEventHandlers() to remove all handlers
}
global UIA := UIA_Interface() ; Defined as a global variable, so it is accessible in ExitFunc as well
h := UIA_CreateEventHandler("EventHandler", "FocusChanged") ; Create a new FocusChanged event handler that calls the function EventHandler (required arguments: element)
UIA.AddFocusChangedEventHandler(h) ; Add a new FocusChangedEventHandler
OnExit("ExitFunc") ; Set up an OnExit call to clean up the handler when exiting the script
return
F5::ExitApp
Code: Select all
#Include <UIA_Interface>
#include <UIA_Browser>
#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
UIA := UIA_Interface()
browserExe := "chrome.exe"
chromeId := WinExist("ahk_exe Chrome.exe")
WinActivate, ahk_id %chromeId%
WinWaitActive, ahk_id %chromeId%
Sleep, 2000
cUIA := new UIA_Browser("ahk_exe " browserExe)
chrome := cUIA.ElementFromHandle(chromeId, True)
Sleep, 2000
Loop, 20
{
Loop, 4
{
chrome.FindFirstBy("Name=FOLLOW AND isOffscreen=0").Click()
Sleep, 400
}
Send, {WheelDown 3}
}
Code: Select all
if (but := chrome.FindFirstBy("Name=FOLLOW AND isOffscreen=0"))
but.Click()
Code: Select all
try {
chrome.FindFirstBy("Name=FOLLOW AND isOffscreen=0").Click()
} catch {
; something went wrong, an exception was thrown or ErrorLevel is raised
}
Code: Select all
#Include <UIA_Interface>
UIA := UIA_Interface()
cacheRequest := UIA.CreateCacheRequest()
cacheRequest.TreeScope := 5 ; Set TreeScope to include the starting element and all descendants as well
cacheRequest.AddProperty("Name")
cacheRequest.AddPattern("Window") ; To use cached patterns, first add the pattern
cacheRequest.AddProperty("WindowCanMaximize") ; Also need to add any pattern properties we wish to use
Run, notepad.exe
WinWaitActive, ahk_exe notepad.exe
npEl:= UIA.ElementFromHandleBuildCache("ahk_exe notepad.exe", cacheRequest) ; Get element and also build the cache
MsgBox, % npEl.DumpAll()
MsgBox, % npEl.CachedWindowPattern.CachedCanMaximize