1

Open File Dialog to interact withI have a Python code that shall interact with a Filedialog Window opened by another software.

I need to insert Filename and Filepath in the File Dialog boxes.

The Python code identifies the window, and write correctly the file name in the file name box.

The software can also identify the item containing the address. I've use this code for this task (function List() below)

def List(): #List of all element in file dialog box


app = Application().connect(title="Open")
dlg = app.window(title="Open")


all_elements = dlg.children()


for element in all_elements:
    print(f"Class Name: {element.class_name()}")
    print(f"Control ID: {element.control_id()}")
    print(f"Control Text: {element.window_text()}")
    print("=" * 40)

In my case item is a ToolbarWindows32, Control id : 1001 The main problem is that i can't write inside it. I can solve by using pyautogui, by entering in the box with the horkey CTRL +L, but I would prefer not to emulate the keys

Here below the code I'm working on:`

from pywinauto import Application

window_name="Open"   
#window_name="Apri"  
app = Application().connect(title=window_name) #Change wit
dlg = app.window(title=window_name)

file_name="Adam2.txt"
file_path = "C:\Test"

#Set the file name in File name box
edit_control_filename = dlg.children(class_name="Edit")
edit_control_filename = edit_control_filename[0] 
edit_control_filename.type_keys(file_name)

#Set the file path in File path box
edit_controls = [control for control in dlg.children(class_name="ToolbarWindow32") if control.control_id() == 1001]
edit_control_filepath = edit_controls[0] 

edit_control_filepath.set_focus()
edit_control_filepath.click_input() 

`

1 Answer 1

0
edit_control_filename.set_edit_text(file_name)

doesn't emulate key actions. Also you can enter the full path to File name: (Nome file:) edit box at once. It should work, and you don't need to enter path separately.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Vasily. Thank you for your answer. Unfortunately it doesn't work... First of all becuase what I'm trying to edit is the filepath, By default that field is not editable, because has a "breadcumb" structure. To get it editable I should select it all. The only way I found is to use the hotkey CTRL +L. But I guess I could avoid this and try to select all by using pywinauto only
Oh, well, this is a bit more tricky and needs some time to figure out. :) Maybe method .invoke() would help for some elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.