title: How do I right click on a windows tray icon and clicking on item on context menu in Python?
body: <p>I need to right click on a Windows Notification Tray icon, and select (left clicking) one of the items on the resulting context menu.</p>
  
  <p>I have tried to use <a href="http://pywinauto.googlecode.com/" rel="nofollow">pywinauto</a>, and while running this code from the code on the <a href="http://pywinauto.googlecode.com/hg/pywinauto/docs/HowTo.html#how-to-access-the-system-tray-aka-systray-aka-notification-area" rel="nofollow">How To's</a> page:
      from pywinauto.application import Application
      from pywinauto import taskbar</p>
  
  <pre><code># connect to outlook
  outlook = Application().connect_(process=4436)
  
  # click on Outlook's icon
  taskbar.ClickSystemTrayIcon(12)
  
  # Select an item in the popup menu
  outlook.PopupMenu.MenuClick("Cancel Server Request")
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\dev\consumertms\temp.py", line 25, in &lt;module&gt;
      taskbar.ClickSystemTrayIcon(12)
    File "C:\Python27\lib\site-packages\pywinauto\taskbar.py", line 52, in ClickSystemTrayIcon
      button = _get_visible_button_index(button)
    File "C:\Python27\lib\site-packages\pywinauto\taskbar.py", line 42, in _get_visible_button_index
      if not SystemTrayIcons.GetButton(i).fsState &amp; \
    File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1878, in GetButton
      button.idCommand)
  RuntimeError: GetButtonInfo failed for button with command id 2
  </code></pre>
  
  <p>I am currently running Windows 8, but will require this to run on Windows XP onwards.</p>
  
  <p>I have searched around and was unable to find a workaround for this.</p>
  
  <p>My Question: Is there a workaround for this error? If not, is there some other Python module I can use to automate this process? Some code snippets will be very much appreciated.</p>
  
  <p>Thanks</p>