0

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.

Ethen12
  • 3
  • 1
  • 2

1 Answers1

1

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

dfuchs
  • 360
  • 2
  • 8
  • Sorry, very new to asking questions here. We are uploading pdf files to a customer's preferred website. I was thinking about using Pywinauto, but I couldn't remember the name of the module to save my life. What we ended up using was pynput. It allowed us to simply say: keyboard.type(filename) – Ethen12 Feb 04 '19 at 19:18
  • For sake of completeness I updated the answer to include a SO link to an example on how to do this by POST request in python. Sounds af if this would be possible here and more simple / less overhead in this case. – dfuchs Feb 04 '19 at 19:29