Jump to content

[SOLVED] How do I read / get the valve of a "read only" field using the UIA UDF?


Recommended Posts

Good morning, I am having a hard time figuring out how to read or get the valve (628850) from the red squared box in the picture below. 

897281675_Screenshot(3).thumb.png.da8fc9a92e5e7cf696f4743b249c0f64.png

Here is what I have tried so far. (see code below. Also, I'm very sorry my code is sloppy.)

 

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
                                                                        ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist)
#include <AD.au3>                                                       ;Allows Active Directory functions
#include <Array.au3>                                                    ;Allows special Array functions
#include <Constants.au3>                                                ;Allows constants to be used
#include <Date.au3>                                                     ;Allows Date and Time functions
#include <DateTimeConstants.au3>                                        ;Allows Date and Time constant functions
#include "DTC.au3"                                                      ;Allows Custom Date and Time functions
#include <IE.au3>                                                       ;Allows Internet Explorer functions
#include <Misc.au3>                                                     ;Allows the "is pressed" function to be used
#include <MsgBoxConstants.au3>                                          ;Allows Message box function to be used
#include <OutlookEX.au3>                                                ;Allows the Outlook functions
#include <String.au3>                                                   ;Allows special string functions
#include <StringConstants.au3>                                          ;Allows String constant functions
#include <Timers.au3>                                                   ;Allows timer functions
;#RequireAdmin                                                          ;Requests admin privliges before starting program

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <debug.au3>
#include <WinAPI.au3>
#include "UIAWrappers.au3"

#AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os


; Sets the script to accept coordinates off the program window and not the screen
AutoItSetOption('MouseCoordMode', 0)
; Defines the time it takes to send text to the software/program
AutoItSetOption('SendKeyDelay', 10)

;*******************************************************************************
; Close the script if "End" is pressed
;*******************************************************************************
Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

HotKeySet("{END}", "Terminate")
Func Terminate()
    MsgBox($MB_ICONINFORMATION, "DEATH", "AI Stoped!", 5)
    Exit
EndFunc


;*******************************************************************************
; Script has started
;*******************************************************************************
Sleep(2000)
MsgBox($MB_ICONINFORMATION, "WO_AI", "AI Started!", 5)
Sleep(1500)

;*******************************************************************************
; Main functions of the program
;*******************************************************************************

test()

;===============================================================================
; Function Definitions
;===============================================================================
Func test()

    MsgBox("", "TESTing", "Timer Started")
    Sleep(15000)
    MsgBox("", "TESTing", "timer Finished")

;~ *** Standard code maintainable ***
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=Work Order Tracking - Google Chrome;controltype:=UIA_PaneControlTypeId;class:=Chrome_WidgetWin_1")    ;Work Order Tracking - Google Chrome
_UIA_setVar("oP2","Title:=Work Order Tracking;controltype:=UIA_DocumentControlTypeId;class:=Chrome_RenderWidgetHostHWND")   ;Work Order Tracking
_UIA_setVar("oP3","Title:=  Work Order Tracking;controltype:=UIA_CustomControlTypeId;class:=")  ;  Work Order Tracking
_UIA_setVar("oP4","Title:=main form;controltype:=UIA_GroupControlTypeId;class:=")   ;main form
_UIA_setVar("oP5","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP6","Title:=View Work Details;controltype:=UIA_CustomControlTypeId;class:=")  ;View Work Details
_UIA_setVar("oP7","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP8","Title:=Location: Location description Long Description Include Children? Include Children: unchecked Include Ancestors? Include Ancestors: unchecked Include History? Include History: unchecked Work Scope Minimize Work Scope Section Minimize Work Scope Section Work Scope Work Close Filter CTRL+Z Close Filter CTRL+Z Filter Filter Table Filter Table Next Row [CTRL+Down Arrow] Next Row [CTRL+Down Arrow] 1 - 4 of 4 Download Hide Table: Work Hide Table: Work Work Work Table Button Group;controltype:=UIA_CustomControlTypeId;class:=") ;Location: Location description Long Description Include Children? Include Children: unchecked Include Ancestors? Include Ancestors: unchecked Include History? Include History: unchecked Work Scope Minimize Work Scope Section Minimize Work Scope Section Work Scope Work Close Filter CTRL+Z Close Filter CTRL+Z Filter Filter Table Filter Table Next Row [CTRL+Down Arrow] Next Row [CTRL+Down Arrow] 1 - 4 of 4 Download Hide Table: Work Hide Table: Work Work Work Table Button Group
_UIA_setVar("oP9","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
_UIA_setVar("oP10","Title:=Work;controltype:=UIA_TableControlTypeId;class:=")   ;Work
_UIA_setVar("oP11","Title:=;controltype:=UIA_CustomControlTypeId;class:=")  ;
_UIA_setVar("oP12","Title:=Record Detail Menu;controltype:=UIA_DataItemControlTypeId;class:=")  ;Record Detail Menu

; Clicks on the main record field
_UIA_setVar("oUIElement","Title:=Record ;controltype:=UIA_EditControlTypeId;class:=") ;ControlType:=UIA_EditControlTypeId;classname:=")

; Trying to click on / get value from the 3rd from top record field (this is me trying to use the id to access the record box)
Local $otest =_UIA_getObjectByFindAll("Record.mainwindow", "id:=ma9038468_tdrow_[C\:1]_txt-tb[R\:3].;ControlType:=UIA_DataItemControlTypeId", $treescope_subtree)


;~ Actions split away from logical/technical definition above can come from configfiles

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")
;~_UIA_Action("oP5","highlight")
_UIA_Action("oP5","setfocus")
;~_UIA_Action("oP6","highlight")
_UIA_Action("oP6","setfocus")
;~_UIA_Action("oP7","highlight")
_UIA_Action("oP7","setfocus")
;~_UIA_Action("oP8","highlight")
_UIA_Action("oP8","setfocus")
;~_UIA_Action("oP9","highlight")
_UIA_Action("oP9","setfocus")
;~_UIA_Action("oP10","highlight")
_UIA_Action("oP10","setfocus")
;~_UIA_Action("oP11","highlight")
_UIA_Action("oP11","setfocus")
;~_UIA_Action("oP12","highlight")
_UIA_Action("oP12","setfocus")

_UIA_action("oUIElement","highlight")
_UIA_Action("oUIElement","setfocus")
_UIA_action("oUIElement","click")

Sleep(2500)

_UIA_action($otest,"highlight")
_UIA_Action($otest,"setfocus")
_UIA_action($otest,"click")


MsgBox("", "End of program", "death")

EndFunc

I'm using $otest to try and click on the box, through the id that chrome gives it, with the UIA functions. I am kind of completely new to the UIA UDF but I do find it capable of doing a lot of cool things.  :) 

as always any help would be greatly appreciated. I know how hard you people hard. Thank you for taking the time to help us. 

Edited by nooneclose
Link to post
Share on other sites

I figured it out. :) 

Here is my finished code that collects the numbers I wanted. 

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
                                                                        ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist)
#include <AD.au3>                                                       ;Allows Active Directory functions
#include <Array.au3>                                                    ;Allows special Array functions
#include <AutoItConstants.au3>
#include <Constants.au3>                                                ;Allows constants to be used
#include <Date.au3>                                                     ;Allows Date and Time functions
#include <DateTimeConstants.au3>                                        ;Allows Date and Time constant functions
#include "DTC.au3"                                                      ;Allows Custom Date and Time functions
#include <IE.au3>                                                       ;Allows Internet Explorer functions
#include <Misc.au3>                                                     ;Allows the "is pressed" function to be used
#include <MsgBoxConstants.au3>                                          ;Allows Message box function to be used
#include <OutlookEX.au3>                                                ;Allows the Outlook functions
#include <String.au3>                                                   ;Allows special string functions
#include <StringConstants.au3>                                          ;Allows String constant functions
#include <Timers.au3>                                                   ;Allows timer functions
;#RequireAdmin                                                          ;Requests admin privliges before starting program

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <debug.au3>
#include <WinAPI.au3>
#include "UIAWrappers.au3"

#AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os


; Sets the script to accept coordinates off the program window and not the screen
AutoItSetOption('MouseCoordMode', 0)
; Defines the time it takes to send text to the software/program
AutoItSetOption('SendKeyDelay', 10)

;*******************************************************************************
; Close the script if "End" is pressed
;*******************************************************************************
Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

HotKeySet("{END}", "Terminate")
Func Terminate()
    MsgBox($MB_ICONINFORMATION, "DEATH", "AI Stoped!", 5)
    Exit
EndFunc


;*******************************************************************************
; Script has started
;*******************************************************************************
Sleep(2000)
MsgBox($MB_ICONINFORMATION, "WO_AI", "AI Started!", 5)
Sleep(1500)


;*******************************************************************************
; Global Variables
;*******************************************************************************
Global $NumOfWork = 0
Global $wOrders[50]


;*******************************************************************************
; Main functions of the program
;*******************************************************************************

Sleep(10000)

FindNumber()
GetOrderNums()


;===============================================================================
; Function Definitions
;===============================================================================

; Find how many work orders are possible duplicates
; This is the number od times the test will need to loop
Func FindNumber()

    MouseClick("Left", 971, 252, 2)

    ; Left click drag from 0, 200 to 600, 700
    MouseClickDrag($MOUSE_CLICK_LEFT, 886, 296, 948, 305)

    Send("^c") ; sends ctrl+c (copy to clip)

    Local $clip = ClipGet() ; sets variable $clip to "copied text"?

    Local $String = StringSplit($clip, "of")

    $NumOfWork = $String[3]

    ; For the loops to work right
    $NumOfWork += 1

    ConsoleWrite(@CRLF & $clip & @CRLF)
    ConsoleWrite(@CRLF & $NumOfWork & @CRLF)

EndFunc


; Get all the numbers in the list
Func GetOrderNums()

    Local $count = 1

    While $count <= $NumOfWork

        If $count <= 1 Then
            AutoItSetOption("MustDeclareVars", 1)

            ; get the work order number
            _UIA_setVar("oP1","Title:=Work Order Tracking - Google Chrome;controltype:=UIA_PaneControlTypeId;class:=Chrome_WidgetWin_1")    ;Work Order Tracking - Google Chrome
            _UIA_setVar("oP2","Title:=Work Order Tracking;controltype:=UIA_DocumentControlTypeId;class:=Chrome_RenderWidgetHostHWND")   ;Work Order Tracking
            _UIA_setVar("oP3","Title:=  Work Order Tracking;controltype:=UIA_CustomControlTypeId;class:=")  ;  Work Order Tracking
            _UIA_setVar("oP4","Title:=main form;controltype:=UIA_GroupControlTypeId;class:=")   ;main form
            _UIA_setVar("oP5","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
            _UIA_setVar("oP6","Title:=Problem Already Reported;controltype:=UIA_CustomControlTypeId;class:=")   ;Problem Already Reported
            _UIA_setVar("oP7","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
            _UIA_setVar("oP9","Title:=;controltype:=UIA_CustomControlTypeId;class:=")   ;
            _UIA_setVar("oP10","Title:=;controltype:=UIA_CustomControlTypeId;class:=")  ;
            _UIA_setVar("oP11","Title:=;controltype:=UIA_CustomControlTypeId;class:=")  ;
            _UIA_setVar("oP12","Title:=;controltype:=UIA_CustomControlTypeId;class:=")  ;
            _UIA_setVar("oP13","Title:=Similar Work Requests Found;controltype:=UIA_TableControlTypeId;class:=")    ;Similar Work Requests Found
            _UIA_setVar("oP14","Title:=;controltype:=UIA_CustomControlTypeId;class:=")  ;
            _UIA_setVar("oP15","Title:=Work Order ;controltype:=UIA_DataItemControlTypeId;class:=") ;Work Order

            ; Get the number
            ;~ $oUIElement=_UIA_getObjectByFindAll("WorkOrder.mainwindow", "title:=Work Order ;ControlType:=UIA_EditControlTypeId", $treescope_subtree)
            _UIA_setVar("oUIElement","Title:=Work Order ;controltype:=UIA_EditControlTypeId;class:=") ;ControlType:=UIA_EditControlTypeId;classname:=")

            Sleep(500)

            ;~_UIA_Action("oP1","highlight")
            _UIA_Action("oP1","setfocus")
            ;~_UIA_Action("oP2","highlight")
            _UIA_Action("oP2","setfocus")
            ;~_UIA_Action("oP3","highlight")
            _UIA_Action("oP3","setfocus")
            ;~_UIA_Action("oP4","highlight")
            _UIA_Action("oP4","setfocus")
            ;~_UIA_Action("oP5","highlight")
            _UIA_Action("oP5","setfocus")
            ;~_UIA_Action("oP6","highlight")
            _UIA_Action("oP6","setfocus")
            ;~_UIA_Action("oP7","highlight")
            _UIA_Action("oP7","setfocus")
            ;~_UIA_Action("oP8","highlight")
            _UIA_Action("oP8","setfocus")
            ;~_UIA_Action("oP9","highlight")
            _UIA_Action("oP9","setfocus")
            ;~_UIA_Action("oP10","highlight")
            _UIA_Action("oP10","setfocus")
            ;~_UIA_Action("oP11","highlight")
            _UIA_Action("oP11","setfocus")
            ;~_UIA_Action("oP12","highlight")
            _UIA_Action("oP12","setfocus")
            ;~_UIA_Action("oP13","highlight")
            _UIA_Action("oP13","setfocus")
            ;~_UIA_Action("oP14","highlight")
            _UIA_Action("oP14","setfocus")
            ;~_UIA_Action("oP15","highlight")
            _UIA_Action("oP15","setfocus")

            _UIA_action("oUIElement","highlight")
            _UIA_action("oUIElement","click")

            $wOrders[$count] = _UIA_action("oUIElement","getvalue")

            ; Move down by one
            Sleep(5000)
            Send("{CTRLDOWN}{DOWN}")
            Send("{CTRLUP}")
            Sleep(5000)
        Else
            _UIA_Action("oP14","setfocus")
            _UIA_Action("oP15","setfocus")
            _UIA_action("oUIElement","highlight")

            $wOrders[$count] = _UIA_action("oUIElement","getvalue")

            ; Move down by one
            Sleep(5000)
            Send("{CTRLDOWN}{DOWN}")
            Send("{CTRLUP}")
            Sleep(5000)
        EndIf

        $count += 1

    WEnd

EndFunc

_ArrayDisplay($wOrders, "Work Order Numbers")

MsgBox("", "End of program", "death")

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Hermes
      Hi, I am struggling in setting the value of a textarea based on the value of clipboard (that contains a long web page source codes). If I use _WD_SetElementValue, it freezes after some time, or appears to be pressing tab and goes out of focus. I can also use send keys but i need the script to run in the background.
      Here is the full script:
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "http://demo.borland.com/testsite/stadyn_largepagewithimages.html") _WD_LoadWait($sSession) Global $sSource = _WD_GetSource($sSession) Local $Paste = ClipPut($sSource) Local $sData = ClipGet() Local $aArray = 0, _ $iOffset = 1 While 1 $aArray = StringRegExp($sData, '(?s)<p>.*</p>', $STR_REGEXPARRAYMATCH, $iOffset) If @error Then ExitLoop $iOffset = @extended For $i = 0 To UBound($aArray) - 1 Local $Paste = ClipPut($aArray[$i]) Local $sRegExData = ClipGet() ;MsgBox(0, "", "$sRegExData = " & $sRegExData) Next WEnd _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_textarea_placeholder") _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") _WD_FrameEnter($sSession, $sElement1) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") $textarea = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") _WD_ElementAction($sSession, $textarea, 'click') ;WD SetElementValue(SsSession, Stextarea, $sRegExData) <-- I can do this but the focus goes out, or the browser freezes _WD_FrameLeave($sSession) sleep(2000) Send("^v") _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Can someone help me please, or re-direct me to the right path? TIA!
    • By ahmet
      Hi,

      I am trying to catch closing of a window via the UIA. End goal is to detect closing of a Chrome's tab, but currently I am having issues with the window created with GUICreate.
      I have modified example from UI Automation Events .
      I added GUI to show issues. Inside this GUI AutomationEventHandler is attached to all buttons. There are two buttons created by the script. One displays the message while the other closes the GUI.
      There are also buttons from the title bar. I attached automation event handlers to those buttons too.
      Currently script notifies me if I click on "OK" button. If I click on any of "Close", "X" or "Minimize" button then I do not get any notification.
      Is it possible for the script to notify when any of the buttons mentioned above is clicked?
      #include "..\Includes\UIAEH_AutomationEventHandler.au3" $hMain=GUICreate("UI Automation Event Handler") $idButtonOK=GUICtrlCreateButton("OK",10,10) $idButtonClose=GUICtrlCreateButton("Close",70,10) $idOutput=GUICtrlCreateEdit("",10,35,300,300) GUISetState() UIAEH_AutomationEventHandlerCreate() If Not IsObj( $oUIAEH_AutomationEventHandler ) Then Exit ConsoleWrite( "$oUIAEH_AutomationEventHandler ERR" & @CRLF ) ConsoleWrite( "$oUIAEH_AutomationEventHandler OK" & @CRLF ) Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation) ;~ Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj($oUIAutomation) Then Exit ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) Local $pIUIAutomationCacheRequest, $oIUIAutomationCacheRequest $oUIAutomation.CreateCacheRequest( $pIUIAutomationCacheRequest ) $oIUIAutomationCacheRequest = ObjCreateInterface( $pIUIAutomationCacheRequest, $sIID_IUIAutomationCacheRequest, $dtag_IUIAutomationCacheRequest ) If Not IsObj( $oIUIAutomationCacheRequest ) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest Error" & @CRLF) If $oIUIAutomationCacheRequest.AddPattern($UIA_InvokePatternId) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.AddPattern Error" & @CRLF) If $oIUIAutomationCacheRequest.put_AutomationElementMode( $AutomationElementMode_Full) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.put_AutomationElementMode Error" & @CRLF) ;~ $pIUIAutomationCacheRequest=0 ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pPane1, $oGUI $oUIAutomation.ElementFromHandle($hMain,$pPane1) $oGUI = ObjCreateInterface($pPane1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oGUI) Then Exit ConsoleWrite("$oGUI ERR" & @CRLF) ConsoleWrite("$oGUI OK" & @CRLF) Local $sNamePropperty, $sClassName1 $oGUI.GetCurrentPropertyValue($UIA_NamePropertyId, $sNamePropperty) ConsoleWrite("Name:" & $sNamePropperty & @CRLF) $oGUI.GetCurrentPropertyValue($UIA_ClassNamePropertyId, $sClassName1) ConsoleWrite("ClassName:" & $sClassName1 & @CRLF) ConsoleWrite("--- Find buttons ---" & @CRLF) Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition0) If Not $pCondition0 Then Exit ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) Local $pButtons, $oButton $oGUI.FindAll($TreeScope_Descendants, $pCondition0, $pButtons) ConsoleWrite("$oGUI FindAll()" & @CRLF) Local $oUIElementArray1, $iLength1 ; $pButtons is a pointer to an UI Automation element array $oUIElementArray1 = ObjCreateInterface($pButtons, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray) $oUIElementArray1.Length($iLength1) If Not $iLength1 Then Exit ConsoleWrite("$iLength1 = 0 ERR" & @CRLF) ConsoleWrite("$iLength1 = " & $iLength1 & @CRLF) ; --- Code Snippets --- ConsoleWrite("--- Code Snippets ---" & @CRLF) Local $pElement1, $oElement1, $pCondition0 Local $sClassName1, $sLocalizedControlType1, $sName1, $hNativeWindowHandle1, $iError For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement($i, $pElement1) $oElement1 = ObjCreateInterface($pElement1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) $oElement1.GetCurrentPropertyValue($UIA_NamePropertyId, $sName1) ConsoleWrite("$sName1 = " & $sName1 & @CRLF) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Children, 0, $oUIAEH_AutomationEventHandler ) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, 0, $oUIAEH_AutomationEventHandler ) $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, $pIUIAutomationCacheRequest, $oUIAEH_AutomationEventHandler ) If $iError Then Exit ConsoleWrite( "AddAutomationEventHandler() ERR" & @CRLF ) ConsoleWrite( "AddAutomationEventHandler() OK" & @CRLF ) Next While Sleep(10) Switch GUIGetMsg() Case -3, $idButtonClose GUIDelete($hMain) MsgBox(0,"About to exit","") Quit() Case $idButtonOK GUICtrlSetData($idOutput,"You clicked on button" & @CRLF,"a") EndSwitch WEnd Func Quit() UIAEH_AutomationEventHandlerDelete() Exit EndFunc ; This is the function that receives events Func UIAEH_AutomationEventHandler_HandleAutomationEvent( $pSelf, $pSender, $iEventId ) ; Ret: long Par: ptr;int ConsoleWrite( @CRLF & "UIAEH_AutomationEventHandler_HandleAutomationEvent: $iEventId = " & $iEventId & @CRLF ) ;~ Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) ; Windows 7 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement2, $dtag_IUIAutomationElement2 ) ; Windows 8 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement3, $dtag_IUIAutomationElement3 ) ; Windows 8.1 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement4, $dtag_IUIAutomationElement4 ) ; Windows 10 First Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ; Windows 10 Last $oSender.AddRef() GUICtrlSetData($idOutput,"InvokedEvent:" & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF,"a") ConsoleWrite( "Title = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Handle = " & "0x" & Hex( UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & _ "Value = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ValueValuePropertyId ) & @CRLF ) MsgBox(0,"","Invoke event") Return 0x00000000 ; $S_OK #forceref $pSelf EndFunc ; Auxiliary function (for simple properties only) ; There must be only one instance of this function Func UIAEH_GetCurrentPropertyValue( $oSender, $iPropertyId ) Local $vPropertyValue $oSender.GetCurrentPropertyValue( $iPropertyId, $vPropertyValue ) Return $vPropertyValue EndFunc  
    • By mLipok
      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • By Hermes
      I have Index.html where it contains a frame with a source "frame1.html". I can select/highlight elements in index.html but unable to select/highlight elements inside the frame with the src "frame1.html", the autoit output is throwing error:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/2143396006437be4005db3b84acc1496/element/8be1c3c4-5bb1-42b1-8cde-7954765cbc61/element; $sData={"using":"css selector","value":"frameset:nth-of-type(1)"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\... __WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"frameset:nth-of-type(1)\"}\n (Session info: chrome=90.0.4430.212)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00FCE7D3+124883]\n\tOrdinal0 [0x00FCE7B1+124849]\n\tGetHandleVerifier [0x01218688+193832]\n\tGetHandleVerifier [0x0123C478+340760]\n\tGetHandleVerifier [0x012361F1+315537]\n\tGetHandleVerifier [0x012516BA+427354]\n\tGetHandleVerifier [0x01236176+315414]\n\tGetHandleVerifier [0x0125174A+427498]\n\tGetHandleVerifier [0x0125D6EB+476555]\n\tGetHandleVerifier [0x0125154B+426987]\n\tGetHandleVerifier [0x01234FFD+310941]\n\tGetHandleVerifier [0x01235D8E+314414]\n\tGetHandleVerifier [0x01235D19+314297]\n\tGetHandleVerifier [0x012F31EC+1089676]\n\tGetHandleVerifier [0x012F17C9+1082985]\n\tGetHandleVerifier [0x012F13A3+1081923]\n\tGetHandleVerifier [0x013ED9FD+2115741]\n\tOrdinal0 [0x0111B82E+1488942]\n\tOrdinal0 [0x010B5A7D+1071741]\n\tOrdinal0 [0x010B559B+1070491]\n\tOrdinal0 [0x010B54B1+1070257]\n\tOrdinal0 [0x010EFF53+1310547]\n\tBaseThreadInitThunk [0x770662C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B34+1028]\n"}} Auto IT Script:
      #Include "wd_core.au3" #Include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'index.html') _WD_LoadWait($sSession) Local $index = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)") Local $index1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index) Local $index2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frame:nth-of-type(1)", $index1) Local $index3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index2) _WD_HighlightElement($sSession, $index2, 1) _WD_HighlightElement($sSession, $index3, 1) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  

      frame1.html index.html
    • By SkysLastChance
      I am using web driver and xpaths to automate chrome. 
      I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 
      This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']") _WD_ElementAction($sSession, $sElement, 'value', "TEST") Here is the html

      Any idea why it is not finding the element inside these pop overs?
       
       
      HTML:
       
×
×
  • Create New...