【问题标题】:Handling Custom ComboBox in pywinauto在 pywinauto 中处理自定义组合框
【发布时间】:2020-12-01 15:49:41
【问题描述】:

我正在编写一个脚本来选择 ComboBox 中的一个区域。我可以使用app.dialog['Region:ComboBox'].select(index),但不能使用app.dialog['Region:ComboBox'].select('string')。我注意到 ComboBox 是自定义的并且是实时生成的。如何使用字符串选择正确的选项?该字符串将是美国西部、美国东部等地区。

   |    | GroupBox - 'Preferences'    (L811, T456, R1108, B593)
   |    | ['PreferencesGroupBox', 'Preferences', 'GroupBox', 'GroupBox0', 'GroupBox1']
   |    | child_window(title="Preferences", control_type="Group")
   |    |    | 
   |    |    | Static - 'PREFERENCES'    (L817, T462, R1102, B476)
   |    |    | ['PREFERENCES', 'PREFERENCESStatic', 'Static25']
   |    |    | child_window(title="PREFERENCES", control_type="Text")
   |    |    | 
   |    |    | Static - 'Region Text:'    (L0, T0, R0, B0)
   |    |    | ['Region Text:Static', 'Region Text:', 'Static26']
   |    |    | child_window(title="Region Text:", control_type="Text")
   |    |    | 
   |    |    | Static - ''    (L0, T0, R0, B0)
   |    |    | ['Static27']
   |    |    | 
   |    |    | Static - 'Region:'    (L822, T498, R937, B512)
   |    |    | ['Region:Static', 'Region:', 'Static28']
   |    |    | child_window(title="Region:", control_type="Text")
   |    |    | 
   |    |    | Custom - ''    (L947, T492, R1097, B518)
   |    |    | ['Custom3', 'Region:Custom']
   |    |    |    | 
   |    |    |    | ComboBox - ''    (L947, T492, R1097, B518)
   |    |    |    | ['ComboBox', 'Region:ComboBox', 'ComboBoxESRI.ArcGIS.Azure.IaaS.Interfaces.RegionInfo']
   |    |    |    |    | 
   |    |    |    |    | Edit - ''    (L0, T0, R0, B0)
   |    |    |    |    | ['Edit', 'Edit0', 'Edit1']
   |    |    |    |    | child_window(auto_id="PART_EditableTextBox", control_type="Edit")
   |    |    | 
   |    |    | Static - 'Remote Desktop Port:'    (L822, T534, R937, B548)
   |    |    | ['Remote Desktop Port:', 'Remote Desktop Port:Static', 'Static29']
   |    |    | child_window(title="Remote Desktop Port:", control_type="Text")
   |    |    | 
   |    |    | Edit - '3389'    (L947, T528, R1097, B554)
   |    |    | ['Edit2', 'Remote Desktop Port:Edit']
   |    |    | child_window(title="3389", control_type="Edit")
   |    |    |    | 
   |    |    |    | ScrollBar - ''    (L0, T0, R0, B0)
   |    |    |    | ['ScrollBar', 'ScrollBar0', 'ScrollBar1']
   |    |    |    | child_window(auto_id="VerticalScrollBar", control_type="ScrollBar")
   |    |    |    | 
   |    |    |    | ScrollBar - ''    (L0, T0, R0, B0)
   |    |    |    | ['ScrollBar2']
   |    |    |    | child_window(auto_id="HorizontalScrollBar", control_type="ScrollBar")
   |    |    |    | 
   |    |    |    | Button - 'r'    (L0, T0, R0, B0)
   |    |    |    | ['r', 'Button8', 'rButton']
   |    |    |    | child_window(title="r", auto_id="PART_ClearText", control_type="Button")
   |    |    | 
   |    |    | CheckBox - 'Track application usage anonymously'    (L822, T564, R1097, B582)
   |    |    | ['Track application usage anonymously', 'CheckBox', 'Track application usage anonymouslyCheckBox', 'Track application usage anonymously0', 'Track application usage anonymously1']
   |    |    | child_window(title="Track application usage anonymously", control_type="CheckBox")
   |    |    |    | 
   |    |    |    | Static - 'Track application usage anonymously'    (L846, T565, R1043, B581)
   |    |    |    | ['Track application usage anonymously2', 'Track application usage anonymouslyStatic', 'Static30']
   |    |    |    | child_window(title="Track application usage anonymously", control_type="Text")

【问题讨论】:

    标签: python ui-automation pywinauto


    【解决方案1】:

    这是我实现它的方式。该函数更有效地模拟了 select() 函数。

    def comboselect(combo,sel):
        combo.type_keys("{ENTER}")          # Selects the combo box
        texts = combo.texts()               #gets all texts available in combo box
        try:
            index = texts.index(str(sel))   #find index of required selection
        except ValueError:
            return False
        sel_index = combo.selected_index()  # find current index of combo
        if(index>sel_index):
            combo.type_keys("{DOWN}"*abs(index-sel_index))
        else:
            combo.type_keys("{UP}"*abs(index-sel_index))
        return True
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多