controlling updown spinner elemnt using pywinauto

170 Views Asked by At

I am trying to control the value of a UpDown spinner element with pywinauto. this is my element i want to control:

UpDown - 'Spinner'    (L384, T624, R400, B642)
   |    |    |    |    | ['Spinner', 'SpinnerUpDown', 'UpDown']
   |    |    |    |    | child_window(title="Spinner", auto_id="68226", control_type="Spinner")

I am not sure how to get it's value and set it's value through pywinauto. i have succeded doing it with button element, but the spinner element is not working while doing the examples and help i found on the internet.

my code goes like this:

from pywinauto.application import Application

app = Application(backend="uia").start('smcg2gui.exe')
# app.PololuSimpleMotorControlCenterG2.print_control_identifiers()
stop_motor = app.PololuSimpleMotorControlCenterG2.child_window(title="Stop motor", auto_id="stopMotorButton", control_type="Button")
speed_controller = app.PololuSimpleMotorControlCenterG2.child_window(title="Spinner", auto_id="7995854", control_type="Spinner")
speed_controller.get_value()
stop_motor.click()
print("done")

and i am getting this error:

Traceback (most recent call last):
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
    ctrl = wait_until_passes(
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
    raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\Users\owner\Desktop\try.py", line 12, in <module>
    speed_controller.get_value()
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
    ctrls = self.__resolve_control(self.criteria)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
    raise e.original_exception
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
    func_val = func(*args, **kwargs)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
    ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'Spinner', 'auto_id': '7995854', 'control_type': 'Spinner', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Pololu Simple Motor Control Center G2', WindowsForms10.Window.8.app.0.33c0d9d, 1835472>, 'backend': 'uia'}

so i tried doing it with wrapper_object:

from pywinauto.application import Application
app = Application(backend="uia").start('smcg2gui.exe')
# app.PololuSimpleMotorControlCenterG2.print_control_identifiers()
stop_motor = app.PololuSimpleMotorControlCenterG2.child_window(title="Stop motor", auto_id="stopMotorButton", control_type="Button")control_type="Button")
speed_controller = app.PololuSimpleMotorControlCenterG2.UpDown.wrapper_object()
print(speed_controller.iface_value.CurrentValue)
stop_motor.click()
print("done")

and got this:

Traceback (most recent call last):
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
    iface = cur_ptrn.QueryInterface(cls_name)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\__init__.py", line 1197, in QueryInterface
    self.__com_QueryInterface(byref(iid), byref(p))
ValueError: NULL COM pointer access
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\Users\owner\Desktop\try.py", line 12, in <module>
    print(speed_controller.iface_value.CurrentValue)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
    value = self.fget(obj)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 252, in iface_value
    return uia_defs.get_elem_interface(elem, "Value")
  File "C:\Users\owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\uia_defines.py", line 236, in get_elem_interface
    raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError

i am a bit lost. Thank you very much

0

There are 0 best solutions below