pywinauto: wait Operation error

Hi Vasily,

I am trying to access outlook.

Based on docs and examples, I am trying below code with wait operation and getting timeout error before application open and visible. What might be best way to use wait operation?

from pywinauto.application import Application 
app = Application().start(r'C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE')
app.rctrl_renwnd32.wait('enabled', timeout = 20) 


Traceback (most recent call last):
  File "C:/Users/rrmamidi/Desktop/old Desktop/compress_1/python/basic python scripts/attache_mail.py", line 9, in <module>
    app.rctrl_renwnd32.wait('enabled', timeout = 20)
  File "C:\Users\rrmamidi\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto-0.6.5-py3.6.egg\pywinauto\application.py", line 502, in wait
    lambda: self.__check_all_conditions(check_method_names, retry_interval))
  File "C:\Users\rrmamidi\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto-0.6.5-py3.6.egg\pywinauto\timings.py", line 370, in wait_until
    raise err
pywinauto.timings.TimeoutError: timed out

Thanks, Raja

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Hi @rajarameshmamidi, just a side note. Did you consider using other ways to automate your task? For example, MS Outlook can be automated through COM interface. I was able to google several examples just in no time. You can use VBA as described here: https://support.microsoft.com/en-nz/help/209948/how-to-use-automation-to-send-a-microsoft-outlook-message-using-access Or have a look at this article, if you prefer stick to Python: https://pbpython.com/windows-com.html

Here a short example heavily based on the above example:

import win32com.client as win32
from pathlib import Path

# Open up an outlook email
outlook = win32.gencache.EnsureDispatch('Outlook.Application')
new_mail = outlook.CreateItem(0)

# Label the subject
new_mail.Subject = "Test Outlook COM automation"

# Add the to and cc list
new_mail.To = "test@mailinator.com"

with open("test.txt", mode="w") as f:
    f.write("Test attachment")

out_file = Path.cwd() / "test.txt"

# The file needs to be a string not a path object
new_mail.Attachments.Add(Source=str(out_file))

# Display the email
new_mail.Display(True)

You can use new_mail.Send() method to actually send the mail

Hi Vasily,

i have installed 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] of python and windows7 64-bit operating system.

Thanks, Raja