pythonpython-3.xwindows-explorerwebbot

How to type into a text field in Windows Explorer?


I am trying to upload a file to a website, and when I click on the upload button (using module WebBot) it opens Windows Explorer. Am I able to output the name of the file into the File Name field? I have the full path of the file, I just need to get the actual text into the File Name box.


Solution

  • I'd consider two approaches here:

    1. Use a python library specifically for interaction with the Windows GUI. I've had good experiences with Pywinauto once, seems still pretty usable at first glance. Hook this in when you expect the explorer window to open. Code may conceptually look like this - do some test run and print all available handles from the upload dialog (just guessing here as a hint, see Pywindocs):

      app = Application().connect(title_re=".*Upload file", path=r"c:\windows\explorer.exe") dlg = app.window(title_re=".*Upload file", path=r"c:\windows\explorer.exe") app.dlg.print_control_identifiers()

    2. Check if you could simply do a POST or similar with the corresponding data. This is a very vague alternative as you do not provide information about what to upload and what the underlying backend/concept of the website is, but in the simplest case this may even be a more elegant option. A quick search brought up this short and simple example for this: https://stackoverflow.com/a/43942648/10192615