Reputation: 31
I'm using pywinauto to upload files to a web server. I'm using Selenium to navigate to a page and activate the windows explorer upload dialog, and then call on pywinauto to access the window that was opened. I've been able to do that, but I can only get it to type keys into the file name field. I'm trying to type in the directory field so I can access specific folders, but the TypeKeys method simply does nothing. Only SendKeys seem to work, but it doesn't type the spaces. Here's my code
import pywinauto.keyboard
import pywinauto
import pywinauto.mouse
def inputfileinuploader(filename):
pwa_app = pywinauto.Application().connect(path="C:\Windows/explorer.exe")
w_handle = pywinauto.findwindows.find_windows(title=u'Open', class_name='#32770')[0]
window = pwa_app.window(handle=w_handle)
ctrl = window['Breadcrumb Parent']
ctrl.TypeKeys("folder")
pywinauto.keyboard.SendKeys(u"You Can Make A Difference 1.mp3")
Upvotes: 2
Views: 10997
Reputation: 9991
Method type_keys
sets the focus before typing. So the problem might be in the wrong control focused. If you make sure the cursor is in right place (for example, by ctrl.click_input()
or ctrl.draw_outline()
) but if you suspect type_keys
sets focus incorrectly, one possible workaround is
ctrl.type_keys("folder", with_spaces=True, set_foreground=False)
The same params are applicable for SendKeys
(except set_foreground
).
Upvotes: 3