#! /usr/bin/env python
#Author: XIE TIAN
# -*- coding:utf8 -*-
from __future__ import unicode_literals
import subprocess
import uiautomation as automation
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

class switch(object):
    def __init__(self, value):
        self.value = value
        self.fall = False
    def __iter__(self):
        """Return the match method once, then stop"""
        yield self.match
        raise StopIteration
    def match(self, *args):
        """Indicate whether or not to enter a case suite"""
        if self.fall or not args:
            return True
        elif self.value in args: # changed for v1.5, see below
            self.fall = True
            return True
        else:
            return False

''' to run smoke test cases of a modality.
[param][in] Main Windows Name e.g PatientAdmin
[param][in] Control Type
[param][in] Control Name
[param][in] Control AutomationId
'''
def FindControlObj(mainWindow, controlType,controlName,controlAutomationId):

type = sys.getfilesystemencoding()       
    mainWindow = mainWindow.decode('gb2312')
    
    controlType=controlType.decode('utf-8').encode(type)
    
    controlName=controlName.decode('gb2312')
    
    controlAutomationId=controlAutomationId.decode('utf-8').encode(type)
    
    
    if mainWindow=="":
        wpfWindow=None
    else:
        wpfWindow=automation.WindowControl(Name=mainWindow)
        
    if controlName=="":
        controlName=None
    if controlAutomationId=="":
        controlAutomationId=None

for case in switch(controlType.lower()):
            if case('button'):
                button=automation.ButtonControl(searchFromControl = wpfWindow,Name=controlName,AutomationId=controlAutomationId)
                result=automation.WaitForExist(button,30)
                if result==True:
                    return button
                else:
                    print 'control not found'
                break
            if case('radiobutton'):
                if controlName=="":
                    radioButton=automation.RadioButtonControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(radioButton,30)
                    if result==True:
                        return radioButton
                    else:
                        print 'control not found'

else:
                    radioButton=automation.RadioButtonControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(radioButton,30)
                    if result==True:
                        return radioButton
                    else:
                        print 'control not found'
                break
            if case('edit'):
                if controlName=="":
                    edit = automation.EditControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(edit,30)
                    if result==True:
                        return edit
                    else:
                        print 'control not found'
                   
                else:
                    edit = automation.EditControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(edit,30)
                    if result==True:
                        return edit
                    else:
                        print 'control not found'
                break
            if case('checkbox'):
                if controlName=="":
                    checkbox = automation.CheckBoxControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(checkbox,30)
                    if result==True:
                        return checkbox
                    else:
                        print 'control not found'
                    
                else:
                    checkbox = automation.CheckBoxControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(checkbox,30)
                    if result==True:
                        return checkbox
                    else:
                        print 'control not found'

break
            if case('combobox'):
                if controlName=="":
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(combobox,30)
                    if result==True:
                        return combobox
                    else:
                        print 'control not found'

else:
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(combobox,30)
                    if result==True:
                        return combobox
                    else:
                        print 'control not found'
                    
                break
            if case('tabitem'):
                if controlName=="":
                    tabitem = automation.TabItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(tabitem,30)
                    if result==True:
                        return tabitem
                    else:
                        print 'control not found'

else:
                    tabitem = automation.TabItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(tabitem,30)
                    if result==True:
                        return tabitem
                    else:
                        print 'control not found'

break
            if case('listitem'):
                if freeParameter<>"":
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,AutomationId=freeParameter)
                    left, top, right, bottom = combobox.BoundingRectangle
                    automation.Click(right-5,bottom-5,1)
                    listitem = automation.ListItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    return listitem
                else:
                    if controlName=="":
                        listitem = automation.ListItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                        return listitem
                    else:
                        listitem = automation.ListItemControl(searchFromControl = wpfWindow,Name=controlName)
                        return listitem
                break
            if case('text'):
                if controlName=="":
                    text = automation.TextControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(text,30)
                    if result==True:
                        return text
                    else:
                        print 'control not found'

else:
                    text = automation.TextControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(text,30)
                    if result==True:
                        return text
                    else:
                        print 'control not found'

break
            
            if case('image'):
                if controlName=="":
                    iamge = automation.ImageControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(image,30)
                    if result==True:
                        return iamge
                    else:
                        print 'control not found'

else:
                    iamge = automation.ImageControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(image,30)
                    if result==True:
                        return iamge
                    else:
                        print 'control not found'

break
            
            if case('menuitem'):
                if controlName=="":
                    menuitem = automation.MenuItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(menuitem,30)
                    if result==True:
                        return menuitem
                    else:
                        print 'control not found'

else:
                    menuitem = automation.MenuItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(menuitem,30)
                    if result==True:
                        return menuitem
                    else:
                        print 'control not found'

break

if case('list'):
                if controlName=="":
                    list = automation.ListControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(list,30)
                    if result==True:
                        return list
                    else:
                        print 'control not found'

else:
                    list = automation.ListControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(list,30)
                    if result==True:
                        return list
                    else:
                        print 'control not found'

break
            if case('progressbar'):
                if controlName=="":
                    progressbar = automation.ProgressBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(progressbar,30)
                    if result==True:
                        return progressbar
                    else:
                        print 'control not found'

else:
                    progressbar = automation.ProgressBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(progressbar,30)
                    if result==True:
                        return progressbar
                    else:
                        print 'control not found'
                break
            
            if case('slider'):
                if controlName=="":
                    slider = automation.SliderControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(slider,30)
                    if result==True:
                        return slider
                    else:
                        print 'control not found'
                    
                else:
                    slider = automation.SliderControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(slider,30)
                    if result==True:
                        return slider
                    else:
                        print 'control not found'

break
            
            if case('custom'):
                if controlName=="":
                    custom = automation.CustomControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(custom,30)
                    if result==True:
                        return custom
                    else:
                        print 'control not found'

else:
                    custom = automation.CustomControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(custom,30)
                    if result==True:
                        return custom
                    else:
                        print 'control not found'
                break
            
            if case('scrollbar'):
                if controlName=="":
                    scrollbar = automation.ScrollBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(scrollbar,30)
                    if result==True:
                        return scrollbar
                    else:
                        print 'control not found'
                else:
                    scrollbar = automation.ScrollBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(scrollbar,30)
                    if result==True:
                        return scrollbar
                    else:
                        print 'control not found'
                break

if case('tab'):
                if controlName=="":
                    tab = automation.TabControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(tab,30)
                    if result==True:
                        return tab
                    else:
                        print 'control not found'

else:
                    tab = automation.TabControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(tab,30)
                    if result==True:
                        return tab
                    else:
                        print 'control not found'

break

if case('treeitem'):
                if controlName=="":
                    treeitem = automation.TreeItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(treeitem,30)
                    if result==True:
                        return treeitem
                    else:
                        print 'control not found'

else:
                    treeitem = automation.TreeItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(treeitem,30)
                    if result==True:
                        return treeitem
                    else:
                        print 'control not found'
                break

if case('datagrid'):
                if controlName=="":
                    datagrid = automation.DataGridControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(datagrid,30)
                    if result==True:
                        return datagrid
                    else:
                        print 'control not found'

else:
                    datagrid = automation.DataGridControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(datagrid,30)
                    if result==True:
                        return datagrid
                    else:
                        print 'control not found'
                break
            
            if case('table'):
                if controlName=="":
                    table = automation.TableControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(table,30)
                    if result==True:
                        return table
                    else:
                        print 'control not found'

else:
                    table = automation.TableControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(table,30)
                    if result==True:
                        return table
                    else:
                        print 'control not found'

break
            
            if case('toolbar'):
                if controlName=="":
                    toolbar = automation.ToolBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(toolbar,30)
                    if result==True:
                        return toolbar
                    else:
                        print 'control not found'

else:
                    toolbar = automation.ToolBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(toolbar,30)
                    if result==True:
                        return toolbar
                    else:
                        print 'control not found'

break

if case('calendar'):
                if controlName=="":
                    calendar = automation.CalendarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(calendar,30)
                    if result==True:
                        return calendar
                    else:
                        print 'control not found'

else:
                    calendar = automation.CalendarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(calendar,30)
                    if result==True:
                        return calendar
                    else:
                        print 'control not found'
                break

if case('pane'):
                if controlName=="":
                    pane = automation.PaneControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(pane,30)
                    if result==True:
                        return pane
                    else:
                        print 'control not found'

else:
                    pane = automation.PaneControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(pane,30)
                    if result==True:
                        return pane
                    else:
                        print 'control not found'

break
            if case('headeritem'):
                if controlName=="":
                    headeritem = automation.HeaderItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(headeritem,30)
                    if result==True:
                        return headeritem
                    else:
                        print 'control not found'

else:
                    headeritem = automation.HeaderItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(headeritem,30)
                    if result==True:
                        return headeritem
                    else:
                        print 'control not found'

break
 
            if case(): # default, could also just omit condition or 'if True'
               print "something else:!"
                # No need to break here, it'll stop anyway

''' to run smoke test cases of a modality.
[param][in] Main Windows Name e.g PatientAdmin
[param][in] Control Type
[param][in] Control Name
[param][in] Control AutomationId
[param][in] FreeParameter e.g. when control is editbox, this value will be the input value, if the control is combox, the parameter is index
'''
def FindControl(mainWindow, controlType,controlName,controlAutomationId,freeParameter):

type = sys.getfilesystemencoding()       
    mainWindow = mainWindow.decode('gb2312')
    
    controlType=controlType.decode('utf-8').encode(type)
    
    controlName=controlName.decode('gb2312')
    
    controlAutomationId=controlAutomationId.decode('utf-8').encode(type)
    
    freeParameter=freeParameter.decode('gb2312')
    
    if mainWindow=="":
        wpfWindow=None
    else:
        wpfWindow=automation.WindowControl(Name=mainWindow)
    if controlName=="":
        controlName=None
    if controlAutomationId=="":
        controlAutomationId=None
    
    for case in switch(controlType.lower()):
            if case('button'):
                print controlName
                print controlAutomationId
                button=automation.ButtonControl(searchFromControl = wpfWindow,Name=controlName,AutomationId=controlAutomationId)
                result=automation.WaitForExist(button,30)
                if result==True:
                    button.Click()
                else:
                    print 'control not found'
                break
            if case('radiobutton'):
                if controlName=="":
                    radioButton=automation.RadioButtonControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(radioButton,30)
                    if result==True:
                        radioButton.Click()
                    else:
                        print 'control not found'

else:
                    radioButton=automation.RadioButtonControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(radioButton,30)
                    if result==True:
                        radioButton.Click()
                    else:
                        print 'control not found'
                break
            if case('edit'):
                if controlName=="":
                    edit = automation.EditControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(edit,30)
                    if result==True:
                        edit.SetValue(freeParameter)
                    else:
                        print 'control not found'
                   
                else:
                    edit = automation.EditControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(edit,30)
                    if result==True:
                        edit.SetValue(freeParameter)
                    else:
                        print 'control not found'
                break
            if case('checkbox'):
                if controlName=="":
                    checkbox = automation.CheckBoxControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(checkbox,30)
                    if result==True:
                        checkbox.Click()
                    else:
                        print 'control not found'
                    
                else:
                    checkbox = automation.CheckBoxControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(checkbox,30)
                    if result==True:
                        checkbox.Click()
                    else:
                        print 'control not found'

break
            if case('combobox'):
                if controlName=="":
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(combobox,30)
                    if result==True:
                        combobox.Select(freeParameter)
                    else:
                        print 'control not found'

else:
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(combobox,30)
                    if result==True:
                        combobox.Select(freeParameter)
                    else:
                        print 'control not found'
                    
                break
            if case('tabitem'):
                if controlName=="":
                    tabitem = automation.TabItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(tabitem,30)
                    if result==True:
                        tabitem.Click()
                    else:
                        print 'control not found'

else:
                    tabitem = automation.TabItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(tabitem,30)
                    if result==True:
                        tabitem.Click()
                    else:
                        print 'control not found'

break
            if case('listitem'):
                if freeParameter<>"":
                    combobox = automation.ComboBoxControl(searchFromControl = wpfWindow,AutomationId=freeParameter)
                    left, top, right, bottom = combobox.BoundingRectangle
                    automation.Click(right-5,bottom-5,1)
                    listitem = automation.ListItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    listitem.Click()
                else:
                    if controlName=="":
                        listitem = automation.ListItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                        listitem.Select()
                    else:
                        listitem = automation.ListItemControl(searchFromControl = wpfWindow,Name=controlName)
                        listitem.Select()
                break
            if case('text'):
                if controlName=="":
                    text = automation.TextControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(text,30)
                    if result==True:
                        text.Click()
                    else:
                        print 'control not found'

else:
                    text = automation.TextControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(text,30)
                    if result==True:
                        text.Click()
                    else:
                        print 'control not found'

break
            
            if case('image'):
                if controlName=="":
                    iamge = automation.ImageControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(image,30)
                    if result==True:
                        image.Click()
                    else:
                        print 'control not found'

else:
                    iamge = automation.ImageControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(image,30)
                    if result==True:
                        image.Click()
                    else:
                        print 'control not found'

break
            
            if case('menuitem'):
                if controlName=="":
                    menuitem = automation.MenuItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(menuitem,30)
                    if result==True:
                        menuitem.Click()
                    else:
                        print 'control not found'

else:
                    menuitem = automation.MenuItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(menuitem,30)
                    if result==True:
                        menuitem.Click()
                    else:
                        print 'control not found'

break

if case('list'):
                if controlName=="":
                    list = automation.ListControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(list,30)
                    if result==True:
                        list.Click()
                    else:
                        print 'control not found'

else:
                    list = automation.ListControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(list,30)
                    if result==True:
                        list.Click()
                    else:
                        print 'control not found'

break
            if case('progressbar'):
                if controlName=="":
                    progressbar = automation.ProgressBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(progressbar,30)
                    if result==True:
                        progressbar.Click()
                    else:
                        print 'control not found'

else:
                    progressbar = automation.ProgressBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(progressbar,30)
                    if result==True:
                        progressbar.Click()
                    else:
                        print 'control not found'
                break
            
            if case('slider'):
                if controlName=="":
                    slider = automation.SliderControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(slider,30)
                    if result==True:
                        slider.Click()
                    else:
                        print 'control not found'
                    
                else:
                    slider = automation.SliderControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(slider,30)
                    if result==True:
                        slider.Click()
                    else:
                        print 'control not found'

break
            
            if case('custom'):
                if controlName=="":
                    custom = automation.CustomControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(custom,30)
                    if result==True:
                        custom.Click()
                    else:
                        print 'control not found'

else:
                    custom = automation.CustomControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(custom,30)
                    if result==True:
                        custom.Click()
                    else:
                        print 'control not found'
                break
            
            if case('scrollbar'):
                if controlName=="":
                    scrollbar = automation.ScrollBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(scrollbar,30)
                    if result==True:
                        scrollbar.Click()
                    else:
                        print 'control not found'
                else:
                    scrollbar = automation.ScrollBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(scrollbar,30)
                    if result==True:
                        scrollbar.Click()
                    else:
                        print 'control not found'
                break

if case('tab'):
                if controlName=="":
                    tab = automation.TabControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(tab,30)
                    if result==True:
                        tab.Click()
                    else:
                        print 'control not found'

else:
                    tab = automation.TabControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(tab,30)
                    if result==True:
                        tab.Click()
                    else:
                        print 'control not found'

break

if case('treeitem'):
                if controlName=="":
                    treeitem = automation.TreeItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(treeitem,30)
                    if result==True:
                        treeitem.Click()
                    else:
                        print 'control not found'

else:
                    treeitem = automation.TreeItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(treeitem,30)
                    if result==True:
                        treeitem.Click()
                    else:
                        print 'control not found'
                break

if case('datagrid'):
                if controlName=="":
                    datagrid = automation.DataGridControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(datagrid,30)
                    if result==True:
                        datagrid.Click()
                    else:
                        print 'control not found'

else:
                    datagrid = automation.DataGridControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(datagrid,30)
                    if result==True:
                        datagrid.Click()
                    else:
                        print 'control not found'
                break
            
            if case('table'):
                if controlName=="":
                    table = automation.TableControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(table,30)
                    if result==True:
                        table.Click()
                    else:
                        print 'control not found'

else:
                    table = automation.TableControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(table,30)
                    if result==True:
                        table.Click()
                    else:
                        print 'control not found'

break
            
            if case('toolbar'):
                if controlName=="":
                    toolbar = automation.ToolBarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(toolbar,30)
                    if result==True:
                        toolbar.Click()
                    else:
                        print 'control not found'

else:
                    toolbar = automation.ToolBarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(toolbar,30)
                    if result==True:
                        toolbar.Click()
                    else:
                        print 'control not found'

break

if case('calendar'):
                if controlName=="":
                    calendar = automation.CalendarControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(calendar,30)
                    if result==True:
                        calendar.Click()
                    else:
                        print 'control not found'

else:
                    calendar = automation.CalendarControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(calendar,30)
                    if result==True:
                        calendar.Click()
                    else:
                        print 'control not found'
                break

if case('pane'):
                if controlName=="":
                    pane = automation.PaneControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(pane,30)
                    if result==True:
                        pane.Click()
                    else:
                        print 'control not found'

else:
                    pane = automation.PaneControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(pane,30)
                    if result==True:
                        pane.Click()
                    else:
                        print 'control not found'

break
            if case('headeritem'):
                if controlName=="":
                    headeritem = automation.HeaderItemControl(searchFromControl = wpfWindow,AutomationId=controlAutomationId)
                    result=automation.WaitForExist(headeritem,30)
                    if result==True:
                        headeritem.Click()
                    else:
                        print 'control not found'

else:
                    headeritem = automation.HeaderItemControl(searchFromControl = wpfWindow,Name=controlName)
                    result=automation.WaitForExist(headeritem,30)
                    if result==True:
                        headeritem.Click()
                    else:
                        print 'control not found'

break
 
            if case(): # default, could also just omit condition or 'if True'
               print "something else:!"
                # No need to break here, it'll stop anyway
    
 
    
if __name__ == '__main__':
    FindControl(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5])

python+UIAutomation+libary的更多相关文章

  1. 使用python UIAutomation从QQ2017(v8.9)群界面获取所有群成员详细资料,

    首先安装pip install uiautomation, 运行本文代码.或者下载https://github.com/yinkaisheng/Python-UIAutomation-for-Wind ...

  2. 使用python uiautomation从钉钉网页版提取公司所有联系人信息

    之前写了一个提取QQ群里所有人信息的脚本 https://www.cnblogs.com/Yinkaisheng/p/5114932.html 今天写一个从钉钉网页版提取公司所有人通讯录的脚本,,本脚 ...

  3. python 常用模块(转载)

    转载地址:http://codeweblog.com/python-%e5%b8%b8%e7%94%a8%e6%a8%a1%e5%9d%97/ adodb:我们领导推荐的数据库连接组件bsddb3:B ...

  4. 常用的python模块

    http://tiankonghaikuo1000.blog.163.com/blog/static/18231597200812424255338/ adodb:我们领导推荐的数据库连接组件bsdd ...

  5. 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt

    首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ...

  6. Python将是人工智能时代的最佳编程语言

    Python将是人工智能时代的最佳编程语言 移动互联网取代PC互联网领跑在互联网时代的最前沿,Android和iOS一度成为移动互联网应用平台的两大霸主,成为移动开发者首选的两门技术,HTML5以其跨 ...

  7. python 常库介绍及安装方法

    bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctypes:用来调用动态链接库DBUtils:数 ...

  8. python开发_常用的python模块及安装方法

    adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctype ...

  9. 常用的python模块及安装方法

    adodb:我们领导推荐的数据库连接组件 bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctyp ...

随机推荐

  1. PowerShell批量创建文件夹

    效果如下: 实现关键: mkdir (1..10|%{"hwllo$_"}) 过程概述:

  2. Android学习笔记_40_系统结构 目录结构

    1.系统结构: 一.应用程序层 Android平台不仅仅是操作系统,也包含了许多应用程序,诸如SMS短信客户端程序.电话拨号程序.图片浏览器.Web浏览器等应用程序.这些应用程序都是用Java语言编写 ...

  3. android 多线程 异步消息处理 服务 学习笔记 (六)

    三种多线程编程方法 1 class Mythread extends Thread{ @Override public void run(){} } new Mythread().start() 2 ...

  4. 常用的linux指令整理

    ls 列出文件目录 -a全部文件,连同隐藏文件一起列出 -d仅列出目录本身,而不是列出目录内的文件数据 -l 连同权限一同列出 cd 切换文件目录的命令 pwd显示目前所在的目录 mkdir 创建新的 ...

  5. SQL3120W 不能将xx的字段值转换成 INTEGER值

    一次用DB2 Load/Import导入数据时,报错,提示SQL3120W 不能将xx的字段值转换成 INTEGER值,但目标列不可为空.未装入该行. 目标表: CREATE TABLE TEST( ...

  6. NEC css规范

    CSS规范 - 分类方法 SS文件的分类和引用顺序 通常,一个项目我们只引用一个CSS,但是对于较大的项目,我们需要把CSS文件进行分类. 我们按照CSS的性质和用途,将CSS文件分成“公共型样式”. ...

  7. ETO的公开赛T2《宏聚变》 题解(BY 萌萌哒123456 )

    我们注意到这道题中最多有 $(n+q)$ 个数被加入,而每个数最多被删除一次,因此每次操作 $O(logn)$的复杂度是可以接受的. 我们对于$1..100000$之间每个数分别开一个set,维护这个 ...

  8. 老刘的Linux小课堂开课了

    经过几个月的等待,刘遄老师的LINUX课堂终于开课了,从现在开始,我会在博客里将每一堂课的笔记记录下来,记录自己的每一步成长. 由于是第一次开课,老刘只是简单的介绍了LINUX相关的一些概念,比如开源 ...

  9. (转)Dubbo 简单Dome搭建

    (转)原地址https://blog.csdn.net/noaman_wgs/article/details/70214612/ Dubbo背景和简介 Dubbo开始于电商系统,因此在这里先从电商系统 ...

  10. 关于linux命令的说明

    开始前我们必须先认识绝对路径与相对路径 绝对路径是从盘符开始的路径 :例如:/etc/sysconfig/network (从根直接指到network) 相对路径是从当前自己所在位置开始的路径:例如我 ...