我正在尝试找到一种方法来创建一个python脚本,找到excel文档中的所有按钮/复选框,并随机地与它们进行交互.
我尝试过使用pywinauto,但它没有在文档中找到实际的对象(可能是因为它是一个vb对象,而不是常规的GUI).
如何使用python完成?或许还有另一种方法可以做到这一点?
这是一个例如excel的文件
谢谢.
我正在使用SHFileOperation()从特定路径中删除目录.它是在多个线程中完成的,删除的目录总是不同的.
它会不时抛出异常:
在del.exe中0x00007FF8AF5D9D2A(ntdll.dll)抛出异常:0xC0000008:指定了无效句柄
还有这个:
在del.exe中0x00007FF8ACC90A36(shell32.dll)抛出异常:0xC0000005:访问冲突读取位置0x0000000000000001.
模块:
shell32.dll 00007FF8ACBD0000-00007FF8AE0D8000
ntdll.dll 00007FF8AF530000-00007FF8AF701000
Run Code Online (Sandbox Code Playgroud)
这是代码:
SHFILEOPSTRUCTW tFileOptions = { 0 };
/* Initialize the file options structure for the deletion process */
tFileOptions.pFrom = pwstrPath;
tFileOptions.wFunc = FO_DELETE;
tFileOptions.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
/* Execute the deletions with the Shell operation */
iResult = SHFileOperationW(&tFileOptions);
if (0 != iResult)
{
printf("WTF\n");
goto lbl_cleanup;
}
SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, pwstrPath, NULL);
Run Code Online (Sandbox Code Playgroud)
pwstrPath最后有一个双空终止符.
这些例外的原因是什么?
编辑
堆栈跟踪:
如果我创建一个线程,它所做的就是连接到某个进程并获得它的顶部窗口,那么程序就会挂起.
我调试了一下它似乎陷入了comtypes._compointer_base.from_params.这是整个追溯:
...
-> self.top_win = self.app.top_window()
c:\python27\lib\site-packages\pywinauto\application.py(1095)top_window()
-> backend=self.backend.name)
c:\python27\lib\site-packages\pywinauto\findwindows.py(197)find_elements()
-> cache_enable=True)
c:\python27\lib\site-packages\pywinauto\uia_element_info.py(272)children()
-> return self._get_elements(IUIA().tree_scope["children"], cond, cache_enable)
c:\python27\lib\site-packages\pywinauto\uia_element_info.py(261)_get_elements()
-> ptrs_array = self._element.FindAll(tree_scope, cond)
> c:\python27\lib\site-packages\comtypes\__init__.py(970)from_param()
-> return value
Run Code Online (Sandbox Code Playgroud)
在pdb中键入步骤后,它显示此然后冻结:
(Pdb) s
--Return--
> c:\python27\lib\site-packages\comtypes\__init__.py(970)from_param()-><POINTER... 41308a0>
-> return value
Run Code Online (Sandbox Code Playgroud)
似乎问题是在线程中使用comtypes,我试图在调用线程(也在main)中调用pythoncom.CoInitialize(),但它没有帮助.
这可以做什么?
谢谢.