0

I am using a program where I have to go through through a series of clicks which eventually the user to upload a file from the file explorer window and select a file to upload.

I have managed to get python to navigate through the menus to get to the file explorer prompt. Is there a way to automatically specify which file to select from the prompt window based on either the file name or extension? I dont want to do it graphically because it could get risky.

So far I only found something to click on a file from a window that the user himself opens:

import subprocess
subprocess.Popen(r'explorer /select,"C:\Users\333\Desktop\123.txt"')

How can I navigate through a file explorer window that opened on its own?

machump
  • 1,051
  • 1
  • 12
  • 30
  • Possible duplicate of: https://stackoverflow.com/questions/9319317/quick-and-easy-file-dialog-in-python – Tomalak May 30 '17 at 17:15
  • can you tell me which post shows how to navigate a file explorer prompted from a program? I can't post comments in that question thread. – machump May 30 '17 at 17:41
  • Pick one of the answers and follow the suggestions. Opening an Explorer window through `subprocess.Popen` will not get you anywhere. An Explorer window is not a file picker. – Tomalak May 30 '17 at 17:44
  • I tried the accepted best answer, it opened a separate dialog box with files, but selecting a file does not select the file for the program I am working with. How come? – machump May 30 '17 at 19:20
  • Hm, maybe I understood your question wrong. You should post more of your code, the one line so far does not give a lot of context. – Tomalak May 30 '17 at 19:47
  • my current code (50+ lines)maximizes the window size for a proprietary program and then graphically navigates to and clicks a "browse" button that opens a Windows file explorer window using pyautogui. I was wondering if there's a module/library to "speak" to the file explorer window and select a file. I'd like to avoid using pyautogui to do interact with the file explorer window that opens (if it is possible). Thanks! – machump May 30 '17 at 19:53
  • Ahh, understood. Scratch my previous comments. Maybe you could try to work out the series of keyboard commands that select the proper file in the Explorer Window and then use some Python "sendkeys" implementation to replicate them if graphical clicks are too wonky for your taste. Sorry that I can't provide sample code for that idea. – Tomalak May 30 '17 at 20:13
  • I'm seeking something along the lines of this: https://stackoverflow.com/questions/19116392/how-to-handle-windows-file-browse-window-using-selenium-webdriver except not from a browser – machump May 31 '17 at 20:35

0 Answers0