Uploading files to the browser using win32

45 Views Asked by At

I need to load files into the browser to submit the form This action needs to be done periodically for data in my working registry

Due to company information security, I can't use Selenium

Using win32, I got to the point where downloading files is necessary. When I open a folder, I don't understand how to gain control over it? How to convey your path? How to select the required files? And how to press the send button?

I was able to get around this problem only using shell.SendKeys

However, this method is not reliable. It seems to me that an error can occur at any time.

# Copy path to clipboard
addToClipBoard(claim_path)

# Get focus on folder
activate_window(dialog_title)
time.sleep(2)

# Walk to enter file path, TABx5
for _ in range(5):
    time.sleep(0.5)
    shell.SendKeys('{TAB}')
time.sleep(0.5)
shell.SendKeys('{ENTER}')
time.sleep(0.5)

# Paste the path to the file folder, Ctrl+v and ENTER
shell.SendKeys(r'^(v)')
time.sleep(0.5)
shell.SendKeys('{ENTER}')

# Walk to select files, TABx4
for _ in range(4):
    time.sleep(0.5)
    shell.SendKeys('{TAB}')
time.sleep(1)

# Select all files, Ctrl+a
shell.SendKeys('^(a)') 
time.sleep(1)

# ENTER
shell.SendKeys('{ENTER}')
0

There are 0 best solutions below