python - 尝试对 SAP 应用程序执行操作时出现 COM 错误
问题描述
我们正在使用 Python pywin32 com 库来编写在 Windows 上运行的 SAP GUI 应用程序的脚本。
事情一直到昨天。
现在,在尝试访问下面执行的代码行时maximize()
,我们得到
com_error: (-2147417851, '服务器抛出异常。', None, None)
并在尝试访问 SAP 窗口中的任何对象(代码的最后一行)时出现以下错误。
AttributeError:无法设置属性“.text”。
有人可以帮忙吗?如果需要更多信息,请告诉我。
下面是我们用来获取新脚本会话、启动 SAP 并执行操作的代码片段:
from subprocess import call
import win32com.client
import time
GUIPath = 'C:/Program Files (x86)/SAP/FrontEnd/SAPgui/'
WinTitle = 'SAP'
SID = 'xxxxxx.sap.xxxxx.com'
InstanceNo = 'xx'
shell = win32com.client.Dispatch("WScript.Shell")
cmdString = os.path.join(GUIPath, 'SAPgui.exe') + " " + SID + " " + InstanceNo
call(cmdString)
while not shell.AppActivate(WinTitle):
time.sleep(1)
checkGUIExists = False
while not checkGUIExists:
try:
SAP = win32com.client.GetObject("SAPGUI").GetScriptingEngine
session = SAP.FindById("/app/con[0]/ses[0]") # session
checkGUIExists = True
except:
time.sleep(1)
continue
//The lines failing//
session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd).text = <transaction>
解决方案
推荐阅读
- html - Font-Awesome 5.9.0 图标未显示在浏览器中;但 5.00 版本是
- apache-kafka - Kafka 2.2.0 中现有 ISR 的领导人选举失败
- jquery - 使用 JQuery 验证 OnInput 事件
- typescript - 如何在 JupyterLab 扩展中激活 Codemirror 插件?
- wordpress - 如何将数字从一页复制到另一页并添加或减去它
- google-sheets - 如何用公式计算具有相同背景颜色的月份?
- swiftui - SwiftUI ForEach 类型“_”没有成员“id”
- multithreading - JVM 线程与 tomcat 线程有什么不同,它们是否有一个映射到内核线程的公共池
- sql - 从表 A 中选择不在表 B 中的每一行
- python - 在程序外更改代理时,Scrapy 循环直到失败