2
votes

Using pywinauto to automate a SAP extract. I swear this code -- copied right out of SWAPY -- worked yesterday.

from pywinauto.application import Application

app = Application().Start(cmd_line = u"C:\\'Program Files (x86)'\\SAP\\FrontEnd\\SAPgui\\saplogon.exe")
window = app.Dialog
window.Wait('ready')
edit = window.Edit
edit.ClickInput()

This gives me the following error:

error: Traceback (most recent call last) ~\AppData\Local\Continuum\Anaconda3\lib\site-packages\pywinauto\application.py in start(self, cmd_line, timeout, retry_interval, create_new_console, wait_for_idle, work_dir) 991 work_dir, # If None - use parent's starting directory. --> 992 start_info) # STARTUPINFO structure. 993 except Exception as exc:

error: (2, 'CreateProcess', 'The system cannot find the file specified.')

During handling of the above exception, another exception occurred:

AppStartError Traceback (most recent call last) in () 1 from pywinauto.application import Application 2 ----> 3 app = Application().Start(cmd_line=u"C:\'Program Files (x86)''\SAP\FrontEnd\SAPgui\saplogon.exe") 4 window = app.Dialog 5 window.Wait('ready')

~\AppData\Local\Continuum\Anaconda3\lib\site-packages\pywinauto\application.py in start(self, cmd_line, timeout, retry_interval, create_new_console, wait_for_idle, work_dir) 995 message = ('Could not create the process "%s"\n' 996 'Error returned by CreateProcess: %s') % (cmd_line, str(exc)) --> 997 raise AppStartError(message) 998 999 self.process = dw_process_id

AppStartError: Could not create the process "C:\'Program Files (x86)''\SAP\FrontEnd\SAPgui\saplogon.exe" Error returned by CreateProcess: (2, 'CreateProcess', 'The system cannot find the file specified.')

I'm running Win7 64bit with Python 3.6.4 :: Anaconda custom (64-bit) and pywingui release 222. I can cut and paste the command into a cmd window and it starts the application just fine.

I've changed quotes. Ichanged the string to raw and removed the \\ for a single \ I'm phlummoxxed.

Also - yesterday when it "worked", clicking on the elements in the 740 version of SAP GUI is a real challenge. Is there any trick to overcome how they have obfuscated the user interface?

1
Changing u"C:\\'Program Files (x86)'\\SAP\\FrontEnd\\SAPgui\\saplogon.exe" to r'C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe' resolved the issueHarvey

1 Answers

2
votes

Changing u"C:\\'Program Files (x86)'\\SAP\\FrontEnd\\SAPgui\\saplogon.exe" to r'C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe' resolved the issue