我正在致力于在“ Oracle VM Virtual box”中加载映像文件的自动化,以使用python中的Pywinauto创建虚拟机。我能够自动安装Virtual Box软件,然后启动映像中显示的exe
但是在那之后,我无法使用Pywinauto自动在“ Oracle VM VirtualBox Manager”上执行任何GUI操作(例如,选择“文件菜单”或单击“新建”按钮)。我已附加了用于Oracle VM Virtual的Inspect工具快照框
下面是我要运行的代码
>>> from pywinauto import application
>>> app=application.Application()
>>> app.start(r"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe")
<pywinauto.application.Application object at 0x000001D671679BA8>
>>>app['Oracle VM VirtualBox Manager']['New']
<pywinauto.application.WindowSpecification object at 0x000001D670FB9CC0>
>>> app['Oracle VM VirtualBox Manager']['New'].click()
执行上面显示的click命令后,我得到了错误
错误:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\pywinauto\application.py", line 246, in __resolve_control
criteria)
File "C:\Program Files\Python37\lib\site-packages\pywinauto\timings.py", line 453, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
app['Oracle VM VirtualBox Manager']['New'].click()
File "C:\Program Files\Python37\lib\site-packages\pywinauto\application.py", line 352, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Program Files\Python37\lib\site-packages\pywinauto\application.py", line 249, in __resolve_control
raise e.original_exception
File "C:\Program Files\Python37\lib\site-packages\pywinauto\timings.py", line 431, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\pywinauto\application.py", line 210, in __get_ctrl
ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
File "C:\Program Files\Python37\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'best_match': 'New', 'top_level_only': False, 'parent': <win32_element_info.HwndElementInfo - 'Oracle VM VirtualBox Manager', Qt5QWindowIcon, 68992>, 'backend': 'win32'}
在Inspect工具中,这表明Oracle VM VirtualBox Manager窗口“键盘是否可聚焦”为假,并且这些控件没有自动化ID。
请向我建议执行按钮的命令,然后单击此GUI上的自动化。我是python的新手,无法理解下一步该怎么做。
答案 0 :(得分:0)
如果您使用的是Inspect.exe
,则必须使用Application(backend="uia")
作为入口点。 Getting Started Guide中对此进行了描述。
默认后端是“ win32”,因此如果Spy++
可以看到此按钮,则可以使用它(我想答案是“否”)。