title: Pbixrefresher for Power BI Desktop report refresh/publish error
body: <p>I am trying to refresh power b.i. more frequently than current capability of gateway schedule refresh.</p>
  <p>I found this:
  <a href="https://github.com/dubravcik/pbixrefresher-python" rel="nofollow noreferrer">https://github.com/dubravcik/pbixrefresher-python</a></p>
  <p>Installed and verified I have all required packages installed to run.
  Right now it works fine until the end - where after it refreshes a Save function seems to execute correctly - but the report does not save - and when it tries Publish function - a prompt is created asking if user would like to save and there is a timeout.</p>
  <p>I have tried increasing the time-out argument and adding more wait time in the routine (along with a couple of other suggested ideas from the github issues thread).</p>
  <p>Below is what cmd looks like along with the error - I also added the Main routine of the pbixrefresher file in case there is a different way to save (hotkeys) or something worth trying.  I tried this both as my user and admin in CMD - but wasn't sure if it's possible a permissions setting could block the report from saving.  Thank you for reading any help is greatly appreciated.</p>
  <pre><code>Starting Power BI
  Waiting 15 sec
  Identifying Power BI window
  Refreshing
  Waiting for refresh end (timeout in 100000 sec)
  Saving
  Publish
  Traceback (most recent call last):
  File &quot;c:\python36\lib\site-packages\pywinauto\application.py&quot;, line 258, in __resolve_control
  criteria)
  File &quot;c:\python36\lib\site-packages\pywinauto\timings.py&quot;, line 458, in wait_until_passes
  raise err
  pywinauto.timings.TimeoutError
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
  File &quot;c:\python36\lib\runpy.py&quot;, line 193, in _run_module_as_main
  &quot;main&quot;, mod_spec)
  File &quot;c:\python36\lib\runpy.py&quot;, line 85, in run_code
  exec(code, run_globals)
  File &quot;C:\Python36\Scripts\pbixrefresher.exe_main.py&quot;, line 9, in
  File &quot;c:\python36\lib\site-packages\pbixrefresher\pbixrefresher.py&quot;, line 77, in main
  publish_dialog.child_window(title = WORKSPACE, found_index=0).click_input()
  File &quot;c:\python36\lib\site-packages\pywinauto\application.py&quot;, line 379, in getattribute
  ctrls = self.__resolve_control(self.criteria)
  File &quot;c:\python36\lib\site-packages\pywinauto\application.py&quot;, line 261, in __resolve_control
  raise e.original_exception
  File &quot;c:\python36\lib\site-packages\pywinauto\timings.py&quot;, line 436, in wait_until_passes
  func_val = func(*args, **kwargs)
  File &quot;c:\python36\lib\site-packages\pywinauto\application.py&quot;, line 222, in __get_ctrl
  ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
  File &quot;c:\python36\lib\site-packages\pywinauto\findwindows.py&quot;, line 87, in find_element
  raise ElementNotFoundError(kwargs)
  pywinauto.findwindows.ElementNotFoundError: {'auto_id': 'KoPublishToGroupDialog', 'top_level_only': False, 'parent': &lt;uia_element_info.UIAElementInfo - 'Simple - Power BI Desktop', WindowsForms10.Window.8.app.0.1bb715_r6_ad1, 8914246&gt;, 'backend': 'uia'}
  </code></pre>
  <p>The main routine from pbixrefresher:</p>
  <pre><code>def main():   
      # Parse arguments from cmd
      parser = argparse.ArgumentParser()
      parser.add_argument(&quot;workbook&quot;, help = &quot;Path to .pbix file&quot;)
      parser.add_argument(&quot;--workspace&quot;, help = &quot;name of online Power BI service work space to publish in&quot;, default = &quot;My workspace&quot;)
      parser.add_argument(&quot;--refresh-timeout&quot;, help = &quot;refresh timeout&quot;, default = 30000, type = int)
      parser.add_argument(&quot;--no-publish&quot;, dest='publish', help=&quot;don't publish, just save&quot;, default = True, action = 'store_false' )
      parser.add_argument(&quot;--init-wait&quot;, help = &quot;initial wait time on startup&quot;, default = 15, type = int)
      args = parser.parse_args()
  
      timings.after_clickinput_wait = 1
      WORKBOOK = args.workbook
      WORKSPACE = args.workspace
      INIT_WAIT = args.init_wait
      REFRESH_TIMEOUT = args.refresh_timeout
  
      # Kill running PBI
      PROCNAME = &quot;PBIDesktop.exe&quot;
      for proc in psutil.process_iter():
          # check whether the process name matches
          if proc.name() == PROCNAME:
              proc.kill()
      time.sleep(3)
  
      # Start PBI and open the workbook
      print(&quot;Starting Power BI&quot;)
      os.system('start &quot;&quot; &quot;' + WORKBOOK + '&quot;')
      print(&quot;Waiting &quot;,INIT_WAIT,&quot;sec&quot;)
      time.sleep(INIT_WAIT)
  
      # Connect pywinauto
      print(&quot;Identifying Power BI window&quot;)
      app = Application(backend = 'uia').connect(path = PROCNAME)
      win = app.window(title_re = '.*Power BI Desktop')
      time.sleep(5)
      win.wait(&quot;enabled&quot;, timeout = 300)
      win.Save.wait(&quot;enabled&quot;, timeout = 300)
      win.set_focus()
      win.Home.click_input()
      win.Save.wait(&quot;enabled&quot;, timeout = 300)
      win.wait(&quot;enabled&quot;, timeout = 300)
  
      # Refresh
      print(&quot;Refreshing&quot;)
      win.Refresh.click_input()
      #wait_win_ready(win)
      time.sleep(5)
      print(&quot;Waiting for refresh end (timeout in &quot;, REFRESH_TIMEOUT,&quot;sec)&quot;)
      win.wait(&quot;enabled&quot;, timeout = REFRESH_TIMEOUT)
  
      # Save
      print(&quot;Saving&quot;)
      type_keys(&quot;%1&quot;, win)
      #wait_win_ready(win)
      time.sleep(5)
      win.wait(&quot;enabled&quot;, timeout = REFRESH_TIMEOUT)
  
      # Publish
      if args.publish:
          print(&quot;Publish&quot;)
          win.Publish.click_input()
          publish_dialog = win.child_window(auto_id = &quot;KoPublishToGroupDialog&quot;)
          publish_dialog.child_window(title = WORKSPACE).click_input()
          publish_dialog.Select.click()
          try:
              win.Replace.wait('visible', timeout = 10)
          except Exception:
              pass
          if win.Replace.exists():
              win.Replace.click_input()
          win[&quot;Got it&quot;].wait('visible', timeout = REFRESH_TIMEOUT)
          win[&quot;Got it&quot;].click_input()
  
      #Close
      print(&quot;Exiting&quot;)
      win.close()
  
      # Force close
      for proc in psutil.process_iter():
          if proc.name() == PROCNAME:
              proc.kill()
  
          
  if __name__ == '__main__':
      try:
          main()
      except Exception as e:
          print(e)
          sys.exit(1)
  
  
  
  </code></pre>