SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Oct 2002
    Location
    amsterdam
    Posts
    98
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Automation API in Excel and Visual Basic (VBA)

    Some starting point to do some nice stuff with the automation api from excel and vba perspective
    http://www.sqaforums.com/showflat.ph...mp;Main=672312

  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Automation API in Excel and Visual Basic (VBA)

    An interesting post related to the same topic -http://mechanicalhandshake.blogspot.com/2011_01_01_archive.html

  3. #3
    Member
    Join Date
    Oct 2002
    Location
    amsterdam
    Posts
    98
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    After years I retried stuff in VBA under windows 10 in Excel 2010 and it works still excellent. UIAutomation is so powerfull available in any office VBA environment for those quick testautomation jobs.

    1. Start a new project in VBA
    2. Make a module and a reference to UIAutomationCore.DLL
    3. copy / paste below and rerun to see what you can get

    Sub test()
    Dim oAutomation As New CUIAutomation ' the UI Automation API
    Dim oDesktop As UIAutomationClient.IUIAutomationElement 'Reference to the root element (desktop)
    Dim oTW As UIAutomationClient.IUIAutomationTreeWalker
    Dim oItem As UIAutomationClient.IUIAutomationElement
    Dim oCondition1 As UIAutomationClient.IUIAutomationCondition 'Used for conditional find of controls
    Dim oCondition2 As UIAutomationClient.IUIAutomationCondition 'Used for conditional find of controls
    Dim oCondition3 As UIAutomationClient.IUIAutomationCondition 'Used for conditional find of controls

    Dim oChilds As UIAutomationClient.IUIAutomationElementArray 'Elementarray when controls are found

    Set oDesktop = oAutomation.GetRootElement 'Get reference to the root element (desktop)

    'Just select 2 items on the desktop
    Set oCondition1 = oAutomation.CreatePropertyCondition(UIA_NameProper tyId, "Program Manager")
    Set oCondition2 = oAutomation.CreatePropertyCondition(UIA_NameProper tyId, "Rekenmachine")
    Set oCondition3 = oAutomation.CreateOrCondition(oCondition1, oCondition2)


    Set oChilds = oDesktop.FindAll(TreeScope_Children, oCondition3)
    'Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElem ent.HelpTextProperty, True)
    'If help Is AutomationElement.NotSupported Then
    ' help = "No help available"
    'End If
    'Dim helpText As String = CStr(help)


    'Show all childs that where found
    Debug.Print "approach 1"
    For i = 0 To oChilds.Length - 1
    Debug.Print i & oChilds.GetElement(i).CurrentName & oChilds.GetElement(i).CurrentClassName
    ' elementList is an AutomationElement.
    Next
    Debug.Print

    'Just select all tems on the desktop
    Set oCondition1 = oAutomation.CreateTrueCondition

    Set oChilds = oDesktop.FindAll(TreeScope_Children, oCondition1)
    'Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElem ent.HelpTextProperty, True)
    'If help Is AutomationElement.NotSupported Then
    ' help = "No help available"
    'End If
    'Dim helpText As String = CStr(help)


    'Show all childs that where found
    x = oDesktop.GetCurrentPropertyValue(UIA_RuntimeIdProp ertyId)
    Debug.Print "approach 2"
    For i = 0 To oChilds.Length - 1
    Debug.Print i & oChilds.GetElement(i).CurrentName & oChilds.GetElement(i).CurrentClassName & oChilds.GetElement(i).GetCurrentPropertyValue(UIA_ NamePropertyId)
    ' elementList is an AutomationElement.
    Next
    Debug.Print

    ' Lets show all the items of the desktop with a treewalker
    Set oTW = oAutomation.ControlViewWalker

    'Get the first child of the desktop
    Set oItem = oTW.GetFirstChildElement(oDesktop)
    While Not oItem Is Nothing
    Debug.Print i & oItem.CurrentName & oItem.CurrentClassName
    Set oItem = oTW.GetNextSiblingElement(oItem)
    Wend

    End Sub

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.34%
vBulletin Optimisation provided by vB Optimise v2.7.1 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.3.0 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:49 AM.

Copyright BetaSoft Inc.