Skip to content Skip to sidebar Skip to footer

Using Variables In Place Of Control And Value Pywinauto

How to use variables in place of list of properties (controls=values) to identify the objects? I'm trying to achieve something like below giving me error, 'Can't assign to function

Solution 1:

You only want to replace the value "103" in your originally working code, so that's the really the only part you should change.

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("target_combo_box_property", action='store_true')
    parser.add_argument("target_combo_box_value", type=int)
    parser.add_argument("target_searched_string")

    args = parser.parse_args()    
    app = Application(backend='win32').connect(path="app.exe")
    findWindow = app.Find
    fieldDrpDwn = findWindow.child_window(control_id=args.target_combo_box_value)    
    select_combo_box_item(fieldDrpDwn, args.target_searched_string) 

if __name__ == '__main__':
    main()

Solution 2:

something like below. i need to pass both control and value from external files, hence wanted to use variables in place of both.

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("target_combo_box_property", action='store_true')
    parser.add_argument("target_combo_box_value", type=int)
    parser.add_argument("target_searched_string")

    args = parser.parse_args()    
    app = Application(backend='win32').connect(path="app.exe")
    findWindow = app.Find
    *fieldDrpDwn = findWindow.child_window(**variable=variable**)*    
    select_combo_box_item(fieldDrpDwn, args.target_searched_string) 

if __name__ == '__main__':
    main()

Post a Comment for "Using Variables In Place Of Control And Value Pywinauto"