问题描述
我正在致力于在"Oracle VM Virtual box"中加载映像文件的自动化,以使用python中的Pywinauto创建虚拟机.我能够自动安装Virtual Box软件和之后,可以启动该exe,也如图所示
I am working on the Automation of loading an image file in "Oracle VM Virtual box" to create a virtual machine using Pywinauto in python. I am able to automate the installation of Virtual Box software & after that able to launch the exe also shown in the image
但是在那之后,我无法使用Pywinauto在"Oracle VM VirtualBox Manager"上自动执行任何GUI操作(例如,选择文件菜单"或单击新建"按钮).我已附加了用于Oracle VM Virtual的Inspect工具快照框
But after that I am not able to do any GUI operation on "Oracle VM VirtualBox Manager" (e.g.Selecting File Menu or click New button) automatically using Pywinauto. I have attached the snapshot of Inspect tool for Oracle VM Virtual box
下面是我要运行的代码
>>> 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命令后,我得到了错误
After executing click command shown above I am getting error
错误:
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.
In Inspect tool it is showing that Oracle VM VirtualBox Manager window "Is Keyboard focusable" is false & there is no Automation ID for these controls.
请向我建议执行按钮的命令,然后单击此GUI上的自动化按钮.我是python&的新手无法理解下一步该怎么做.
Please suggest me the commands to perform buttons click automation on this GUI. I am new to python & not able to understand what should I do next.
推荐答案
如果使用的是Inspect.exe
,则必须使用Application(backend="uia")
作为入口点. 入门指南中对此进行了描述.
If you're using Inspect.exe
, you must use Application(backend="uia")
as an entry point. This is described in the Getting Started Guide.
默认后端是"win32",因此如果Spy++
可以看到此按钮,则可以使用它(我想答案是否").
Default backend is "win32", so it can be used if Spy++
can see this button (I suppose the answer is "no").
这篇关于无法自动化按钮,请单击"Oracle VM虚拟框",然后单击“确定".在python中使用pywinauto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!