controlling updown spinner elemnt using pywinauto - python

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

Related

Change the wrapper object to a different class in pywinauto

I'm trying to set a value on this dropdown but am having trouble doing so. I've tried using the .select(index) method and that doesn't do anything. I've tried doing .typekeys("{DOWN 2}"), which usually works, but I think because another dropdown is selected before hand or something, it's not working. My usual workaround for this is to do .expand() and then .type_keys("{DOWN 2}"), and then .type_keys("{ENTER}"). I can't do this last workaround, because the control is not being wrapped as a combobox, as it should be.
Is there a way I can change it's wrapper? I tried:
from pywinauto import controls
test = controls.uia_controls.ComboBoxWrapper(formJobStock.child_window(auto_id='cboStockSize'))
test.expand()
but I get:
Traceback (most recent call last):
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
ctrl = wait_until_passes(
File "C:\Users\mflanagan\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 "<stdin>", line 1, in <module>
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uia_controls.py", line 143, in expand
if self.is_expanded():
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 561, in is_expanded
state = self.get_expand_state()
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uia_controls.py", line 188, in get_expand_state
return super(ComboBoxWrapper, self).get_expand_state()
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 556, in get_expand_state
return self.iface_expand_collapse.CurrentExpandCollapseState
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\controls\uiawrapper.py", line 210, in iface_expand_collapse
return uia_defs.get_elem_interface(elem, "ExpandCollapse")
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\uia_defines.py", line 233, in get_elem_interface
cur_ptrn = element_info.GetCurrentPattern(ptrn_id)
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Users\mflanagan\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\mflanagan\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\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
elements = find_elements(**kwargs)
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 305, in find_elements
elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
File "C:\Users\mflanagan\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findbestmatch.py", line 536, in find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'element' in 'dict_keys(['Edit', 'Edit0', 'Edit1', 'Edit2', 'Open', 'Button', 'OpenButton'])'
where formJobStock is a window specification:
formJobStock = window.child_window(auto_id='frmJobStock')
and I know it's found because I've done formJobStock.wrapper_object() and it comes up correctly.
It looks like I'm not passing in the element parameter correctly to the controls.controls_uia.ComboBoxWrapper class init call...any idea on how to do that correctly?

FramenetError: Unknown frame

I run:
from nltk.corpus import framenet as fn
fn.frames()
And get the following error:
Traceback (most recent call last):
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1308, in frame_by_name
elt = XMLCorpusView(locpath, 'frame')[0]
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 155, in __init__
encoding = self._detect_encoding(fileid)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/xmldocs.py", line 166, in _detect_encoding
with open(fileid, 'rb') as infile:
NotADirectoryError: [Errno 20] Not a directory: '/Users/me/nltk_data/corpora/framenet_v17.zip/framenet_v17/frame/Abandonment.xml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 876, in __repr__
for elt in self:
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/collections.py", line 406, in iterate_from
try: yield self._func(self._lists[0][index])
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1407, in frame
f = self.frame_by_id(fn_fid_or_fname, ignorekeys)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1268, in frame_by_id
return self.frame_by_name(name, ignorekeys, check_cache=False)
File "/Users/me/anaconda3/envs/nlp/lib/python3.6/site-packages/nltk/corpus/reader/framenet.py", line 1310, in frame_by_name
raise FramenetError('Unknown frame: {0}'.format(fn_fname))
nltk.corpus.reader.framenet.FramenetError: Unknown frame: Abandonment
Both the Framenet 1.5 and 1.7 corpora are installed, according to nltk.download()

How to write a unit test for when "During handling of the above exception, another exception occurred"

Unique index constraint in mongoengine throws this exception when I'm trying to save an object with the same id:
|2018-06-28 14:23:28.084| [DEBUG] (rec.exchange.base|26): Processing exchange data
Traceback (most recent call last):
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/mongoengine/document.py", line 372, in save
object_id = self._save_create(doc, force_insert, write_concern)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/mongoengine/document.py", line 428, in _save_create
object_id = collection.save(doc, **write_concern)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/pymongo/collection.py", line 2917, in save
to_save, True, check_keys, manipulate, write_concern)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/pymongo/collection.py", line 599, in _insert
bypass_doc_val, session)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/pymongo/collection.py", line 580, in _insert_one
_check_write_command_response(result)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/pymongo/helpers.py", line 207, in _check_write_command_response
_raise_last_write_error(write_errors)
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/pymongo/helpers.py", line 188, in _raise_last_write_error
raise DuplicateKeyError(error.get("errmsg"), 11000, error)
pymongo.errors.DuplicateKeyError: E11000 duplicate key error collection: TRX.exchanges index: exchange_1_order.id_1 dup key: { : "BFNX", : "1234" }
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 5, in <module>
application.run()
File "/home/nst/Dev/rec/rec/trx_app.py", line 118, in run
self.run_scheduler_app()
File "/home/nst/Dev/rec/rec/trx_app.py", line 106, in run_scheduler_app
self.run_jobs_hook_without_scheduler()
File "/home/nst/Dev/rec/rec/trx_app.py", line 92, in run_jobs_hook_without_scheduler
get_exchange_job(order)
File "/home/nst/Dev/rec/rec/scheduler/job_hooks.py", line 39, in get_exchange_job
ExchangeJob(job_cfg).run()
File "/home/nst/Dev/rec/rec/exchange/job.py", line 22, in run
exchange_data = self.data_source.get_exchange_data()
File "/home/nst/Dev/rec/rec/exchange/base.py", line 15, in get_exchange_data
return self._map_data(self._read_data())
File "/home/nst/Dev/rec/rec/exchange/base.py", line 31, in _read_data
parser = self._build_data_parser()
File "/home/nst/Dev/rec/rec/exchange/impl/bitfinex.py", line 113, in _build_data_parser
ed1.save()
File "/home/nst/virtualenvs/myenv/lib/python3.6/site-packages/mongoengine/document.py", line 395, in save
raise NotUniqueError(message % six.text_type(err))
mongoengine.errors.NotUniqueError: Tried to save duplicate unique keys (E11000 duplicate key error collection: TRX.exchanges index: exchange_1_order.id_1 dup key: { : "BFNX", : "1234" })
I'm trying to write a unit test for this case:
from mongoengine.errors import NotUniqueError
def test_duplicate_exchange_data(self):
order1 = ExchangeOrder(id='1234', currency_pair='tBTGUSD',
datetime=datetime.datetime.today(),
amount=1500, price=57)
exchange_data1 = ExchangeData(exchange='BFNX', order=order1)
exchange_data1.save()
order2 = ExchangeOrder(id='1234', currency_pair='tBTCUSD',
datetime=datetime.datetime.today(),
amount=500, price=57.5)
exchange_data2 = ExchangeData(exchange='BFNX', order=order2)
self.assertRaises(NotUniqueError, exchange_data2.save)
but assertRaises() is not working because of the second exception. How can I handle this in test?

Tuleap LDAP Subversion Browse Svn Tree Issue

I have enabled LDAP on tuleap. But when I go to subversion> Browse SVN tree, I get following error
An Exception Has Occurred
Python Traceback
Traceback (most recent call last): File
"/usr/share/viewvc/lib/viewvc.py", line 3814, in main
request.run_viewvc() File "/usr/share/viewvc/lib/viewvc.py", line 318, in run_viewvc
if not svnaccess.check_read_access(user.user_getname(), self.rootpath, self.where): File
"/usr/share/tuleap/src/www/../utils/svn/svnaccess.py", line 130, in
check_read_access
username = get_name_for_svn_access(svnrepo, username) File "/usr/share/tuleap/src/www/../utils/svn/svnaccess.py", line 119, in
get_name_for_svn_access
return codendildap.get_login_from_username(username) File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 60, in
get_login_from_username
return get_login_from_eduid(row['ldap_id']) File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 43, in
get_login_from_eduid
l = ldap_connect() File "/usr/share/tuleap/src/www/../utils/svn/codendildap.py", line 33, in
ldap_connect
l = ldap.initialize(server) File "/usr/lib64/python2.6/site-packages/ldap/functions.py", line 85, in
initialize
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit) File "/usr/lib64/python2.6/site-packages/ldap/ldapobject.py", line
69, in __init__
self._l = ldap.functions._ldap_function_call(_ldap.initialize,uri) File
"/usr/lib64/python2.6/site-packages/ldap/functions.py", line 57, in
_ldap_function_call
result = func(*args,**kwargs) LDAPError:(0, 'Error')
$sys_ldap_server = 'X.X.X.X:xxx'; $sys_ldap_cn='cn'; $sys_ldap_people_dn='ou=Users,dc=xxxx,dc=org'; $sys_ldap_search_user='(|(uid=%words%)(cn=%words%))'; $sys_ldap_default_user_status='A'; $sys_ldap_svn_auth=1; $sys_ldap_daily_sync=1; $sys_ldap_user_management=1; $sys_ldap_grp_enabled = 1; $sys_ldap_grp_dn='ou=groups,dc=xxxx,dc=org'; $sys_ldap_grp_cn = 'cn'; $sys_ldap_grp_member='uniquemember';
The LDAP server configuration variable should be defined with ldap:// (or ldaps:// for SSL LDAP)

suds.TypeNotFound: Type not found:'ns4.SaveCRRequest'

Does anyone have inputs on how to debug or overcomes this error?
Traceback (most recent call last):
File ".\move2ready.py", line 318, in <module>
main()
File ".\move2ready.py", line 268, in main
success = moveToReady(prism, cr, pl_name)
File ".\move2ready.py", line 153, in moveToReady
retval = prism.saveChangeRequest(CR)
File ".\move2ready.py", line 75, in saveChangeRequest
request = self.soapclient.factory.create('ns4:SaveCRRequest')
File "build\bdist.win32\egg\suds\client.py", line 234, in create
suds.TypeNotFound: Type not found: 'ns4:SaveCRRequest'
Following is the subroutine
def saveChangeRequest(self, CR):
request = self.soapclient.factory.create('ns4:SaveCRRequest')
request['ChangeRequest'] = CR
request['UserName'] = 'admin'
response = self.soapclient.service.SaveChangeRequest([request])
return response['ChangeRequestId']

Categories

Resources