1

I am trying to write a web scraper in python that uploads a file to a website (through a dashboard). To upload a file, I need to click on this box.

File upload box

When I click on this box it opens a File Explorer window. I want to be able to type into the 'File Name:' box.

Windows file explorer I assume it's possible with PyWinAuto but I have never used it before and have no idea how I'm supposed to go about it. The furthest I've got is connecting to the window

app = Application(backend="uia").connect(path="explorer.exe", title="Open")
4
  • Are you sure to be connected to the good window? I think it is the taskbar Try app.top_window().draw_outline() To easily do what you want to do try Pywinauto recorder Commented Jun 2, 2021 at 19:16
  • Do you know how i can target the file explorer window? Commented Jun 2, 2021 at 20:50
  • 1
    Please post your solution as answer and mark it as accepted. It's better signal for others the problem is solved. Thanks! Commented Jun 4, 2021 at 19:27
  • Well done! Vasily is right: posting your solution as an answer and also adding the method by which you found the solution would certainly be of great help to others. Commented Jun 5, 2021 at 7:29

1 Answer 1

2

I managed to figure it out in the end.

Instead of connecting to 'explorer.exe', I had to connect to the browser window that contained the file explorer box using this code.

app = Application(backend='uia').connect(title='Browser window name',timeout=100)

fileBox = app.BrowserWindowName.child_window(title="File name:", auto_id="1148", control_type="Edit").wrapper_object()

This targeted the 'File Name:' box that I was then able to send a file path to by using the type_keys() method

fileBox.type_keys('pathToFile', with_spaces=True)
Sign up to request clarification or add additional context in comments.

2 Comments

set_text() would be a more reliable method instead of type_keys()
@VidyaMarathe not only reliable but is also faster method.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.