使用pywinauto从组合框中选择一个项目

时间:2018-05-10 08:43:46

标签: pywinauto

我正在尝试使用pywinauto自动化Visual Basic应用程序,后端=“win32”。除了从其中一个组合框中选择一个项目之外,我能够处理所有事情。这种特殊的组合框取决于另一种组合框的选择

以下是代码:

-f...

错误相同:

$ cut -d',' -f1,2,3,4,5,9 sample.csv
c1,c2,c3,c4,c5,c9
123,B006195,T,O,INDIVIDUAL,NEW
12,C06195,T,O,INDIVIDUAL,NEW
12345,B00619,T,O,IND,OLD

控制标识符返回:

app.ThunderRT6MDIForm.xxxxx.ComboBox3.select("abc") # this correctly selects from the combobox
app.ThunderRT6MDIForm.xxxxx.ComboBox4.select(1) #This one gives error

3 个答案:

答案 0 :(得分:1)

尝试此方法:(不要忘记传递combo_box元素)

def set_combo_box_item_that_starts_with(combo_box, searched_string):
    for text in combo_box.GetProperties()['texts']:
        if text.startswith(searched_string):
            combo_box.select(searched_string)
    return None

答案 1 :(得分:0)

还有另一个变体:

loginWindow["Edit1"].type_keys("%{DOWN}")
loginWindow.child_window(title="choiceYouWant", control_type="ListItem").click_input()

答案 2 :(得分:0)

以前的答案对我不起作用。

这是我的实现方式。

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
相关问题