Not able to automate button click on “Oracle VM virtual box” using pywinauto in python

被刻印的时光 ゝ 提交于 2019-12-24 16:56:00

问题


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

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

Below is the code which I am trying to run

>>> 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()

After executing click command shown above I am getting error

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'}

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.

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.


回答1:


If you're using Inspect.exe, you must use Application(backend="uia") as an entry point. This is described in the Getting Started Guide.

Default backend is "win32", so it can be used if Spy++ can see this button (I suppose the answer is "no").



来源:https://stackoverflow.com/questions/54866951/not-able-to-automate-button-click-on-oracle-vm-virtual-box-using-pywinauto-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!