How to use staticTextsR method in pyatom

Best Python code snippet using pyatom_python

AXClasses.py

Source:AXClasses.py Github

copy

Full Screen

...1089 return self._convenienceMatchR('AXSheet', 'AXDescription', match)1090 def staticTexts(self, match=None):1091 """Return a list of statictexts with an optional match parameter."""1092 return self._convenienceMatch('AXStaticText', 'AXValue', match)1093 def staticTextsR(self, match=None):1094 """Return a list of statictexts with an optional match parameter"""1095 return self._convenienceMatchR('AXStaticText', 'AXValue', match)1096 def genericElements(self, match=None):1097 """Return a list of genericelements with an optional match parameter."""1098 return self._convenienceMatch('AXGenericElement', 'AXValue', match)1099 def genericElementsR(self, match=None):1100 """Return a list of genericelements with an optional match parameter."""1101 return self._convenienceMatchR('AXGenericElement', 'AXValue', match)1102 def groups(self, match=None):1103 """Return a list of groups with an optional match parameter."""1104 return self._convenienceMatch('AXGroup', 'AXRoleDescription', match)1105 def groupsR(self, match=None):1106 """Return a list of groups with an optional match parameter."""1107 return self._convenienceMatchR('AXGroup', 'AXRoleDescription', match)...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...58 _activate()59 time.sleep(0.1)60 flag = False61 try:62 s = _tdx.windows()[0].staticTextsR('人民币: 余额:*')[0].AXValue63 if len(s) > 0:64 flag = True65 except:66 pass67 if not flag:68 _tdx.windows()[0]._convenienceMatch('AXCheckBox', 'AXTitle', '持仓')[0].Press()69 time.sleep(0.1)70 flag = False71 while not flag:72 try:73 s = _tdx.windows()[0].staticTextsR('人民币: 余额:*')[0].AXValue74 if len(s) > 0:75 flag = True76 break77 except:78 pass79 time.sleep(0.1)80 s = _tdx.windows()[0].staticTextsR('人民币: 余额:*')[0].AXValue81 cash_balance, cash_available, _, stocks_total, assets_total = re.match(82 r'人民币:余额:([\d\.]*)可用:([\d\.]*)可取:([\d\.]*)股票市值:([\d\.]*)资产:([\d\.]*)', s.replace(' ', '')).groups()83 if portfolio:84 portfolio = _table_to_dataframe('累计浮动盈亏').iloc[:, :-1]85 portfolio.set_index('证券代码', inplace=True)86 return (float(cash_balance), float(cash_available), float(stocks_total), float(assets_total)), portfolio87def query_orders():88 global _tdx89 _activate()90 time.sleep(0.1)91 _tdx.windows()[0]._convenienceMatch('AXCheckBox', 'AXTitle', '成交')[0].Press()92 time.sleep(1.8)93 today_orders = _table_to_dataframe('成交日期').iloc[:, :-2]94 print(today_orders)95 _click(_tdx.windows()[0].AXChildren[2]._convenienceMatchR('AXTextField', 'AXValue', ' 历史成交')[0])96 time.sleep(1.8)97 history_orders = _table_to_dataframe('成交日期').iloc[:, :-1]98 print(history_orders)99 import pandas as pd100 orders = pd.concat([today_orders, history_orders])101 return orders102def _table_to_dataframe(header_key):103 global _tdx104 table = _tdx.windows()[0].buttonsR(header_key)[0].AXParent.AXParent105 rows = table._convenienceMatch('AXRow', 'AXRoleDescription', 'table row')106 data = [[column.AXValue for column in row.AXChildren] for row in rows]107 columns = [button.AXTitle for button in table.buttonsR()]108 import pandas as pd109 return pd.DataFrame(data, columns=columns)110def buy(codes, positions):111 # logger.debug('enter buy')112 global _tdx113 _activate()114 time.sleep(0.1)115 # logger.debug('will press buy button')116 _tdx.windows()[0]._convenienceMatch('AXCheckBox', 'AXTitle', '买入')[0].Press()117 time.sleep(0.2)118 codes = [codes] if isinstance(codes, str) else codes119 # logger.debug('loop codes for buy')120 for code, money in zip(codes, positions):121 # logger.debug('target code is: {}'.format(code))122 try:123 time.sleep(0.2)124 # logger.debug('will press order type 1')125 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()126 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()127 types = _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[1].AXChildren[128 0].AXChildren129 type_index = 0130 # logger.debug('will click type option')131 _click(types[type_index])132 time.sleep(0.1)133 # logger.debug('set code focus')134 _tdx.windows()[0].textFields()[0].AXFocused = True135 _tdx.windows()[0].textFields()[0].setString('AXValue', code)136 # _tdx.windows()[0].textFields()[0].Confirm()137 time.sleep(1.5)138 price = _tdx.windows()[0].textFields()[2].AXValue139 price = float(price)140 # logger.debug('price is: {}'.format(price))141 amount = int(money / price / 100) * 100142 if amount < 100:143 print(33)144 # logger.error('money: {} can not buy {} 100 shares, stock price: {}'.format(money, code, price))145 # amount = 100146 # logger.debug('amount is: {}'.format(amount))147 _tdx.windows()[0].textFields()[1].setString('AXValue', amount)148 _tdx.windows()[0].textFields()[1].Confirm()149 time.sleep(0.5)150 # logger.debug('select order type option')151 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()152 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()153 # time.sleep(0.1)154 types = _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[1].AXChildren[155 0].AXChildren156 type_index = 4 if len(types) > 3 else 1157 # logger.debug('click order option: {}'.format(types[type_index]))158 _click(types[type_index])159 time.sleep(0.1)160 if not DEBUG:161 _click(_tdx.windows()[0].buttonsR('买入下单')[0])162 time.sleep(0.2)163 _confirmIfMessage()164 time.sleep(0.5)165 _confirmIfMessage()166 time.sleep(0.2)167 except:168 pass169 # logger.exception('Exception while tdx.buy')170def sell(codes):171 # logger.debug('enter sell')172 global _tdx173 _activate()174 time.sleep(0.1)175 # logger.debug('press the sell button')176 _tdx.windows()[0]._convenienceMatch('AXCheckBox', 'AXTitle', '卖出')[0].Press()177 time.sleep(0.1)178 codes = [codes] if isinstance(codes, str) else codes179 # logger.debug('loop codes for sell')180 for code in codes:181 # logger.debug('target code: {}'.format(code))182 try:183 _tdx.windows()[0].textFields()[0].AXFocused = True184 _tdx.windows()[0].textFields()[0].setString('AXValue', code)185 # _tdx.windows()[0].textFields()[0].Confirm()186 time.sleep(1.5)187 _click(_tdx.windows()[0].buttonsR('全部')[0])188 time.sleep(0.1)189 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()190 _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[0].Press()191 # time.sleep(0.1)192 types = _tdx.windows()[0]._convenienceMatch('AXComboBox', 'AXTitle', None)[1].AXChildren[1].AXChildren[193 0].AXChildren194 type_index = 4 if len(types) > 3 else 1195 # logger.debug('click order option: {}'.format(types[type_index]))196 _click(types[type_index])197 time.sleep(0.1)198 # stop_price = _tdx.windows()[0]._convenienceMatch('AXScrollArea', 'AXTitle', None)[1].AXChildren[0]._convenienceMatch('AXRow', 'AXTitle', None)[-3].AXChildren[1].AXValue199 if not DEBUG:200 _click(_tdx.windows()[0].buttonsR('卖出下单')[0])201 time.sleep(0.2)202 _confirmIfMessage()203 time.sleep(0.2)204 _confirmIfMessage()205 time.sleep(0.2)206 except:207 pass208 # logger.exception('Exception while tdx.sell')209# def query_order(codes, flag=None):210# global _tdx211# _activate()212# time.sleep(0.1)213# _tdx.windows()[0]._convenienceMatchR('AXCheckBox', 'AXTitle', '成交')[0].Press()214# time.sleep(0.2)215#216# codes = [codes] if isinstance(codes, str) else codes217def exit():218 global _tdx219 _activate()220 time.sleep(0.1)221 _tdx.sendKeyWithModifiers('q', [COMMAND_L])222 time.sleep(1)223def lockHide():224 global _tdx225 _activate()226 time.sleep(0.1)227 _tdx.windows()[0].buttonsR('锁定')[0].Press()228 time.sleep(0.1)229 _tdx.windows()[0].buttons()[-1].Press()230 time.sleep(0.1)231def _confirmIfMessage():232 try:233 title = _tdx.windows()[0].AXChildren[1].AXValue234 message = _tdx.windows()[0].AXChildren[2].AXValue235 if title in ('提示', '交易确认', '连接确认'):236 # logger.debug('confirm message {}: {}'.format(title, message))237 button = _tdx.windows()[0].AXChildren[3]238 if button.AXTitle in ('确定', '是'):239 button.Press()240 time.sleep(0.1)241 if 'KCBPCLI_CallProgramAndCommit' in message:242 minutes = 30243 # logger.info('KCBPCLI_CallProgramAndCommit失败, system in maitain, wait {} minutes ...'.format(minutes))244 time.sleep(60 * minutes)245 elif '接收应答超时或网络已断开' in message:246 minutes = 10247 # logger.info('接收应答超时或网络已断开, wait {} minutes...'.format(minutes))248 time.sleep(60 * minutes)249 except:250 pass251def _click(obj):252 position = obj.AXPosition253 size = list(obj.AXSize)254 size[0] = 60. if size[0] > 200 else size[0]255 coord = (position[0] + size[0] / 2, position[1] + size[1] / 2)256 obj.clickMouseButtonLeft(coord)257 time.sleep(0.1)258def _loginFirstIfUnlogin(account, password):259 global _tdx260 try:261 search_text = ''262 try:263 search_text = _tdx.windows()[0].AXChildren[1].AXChildren[1].AXTitle264 except:265 pass266 if len(search_text) > 0:267 if account is None or len(account) < 5 or password is None or len(password) < 6:268 raise Exception('You must assgin correct trade account and password for login!')269 else:270 return271 if _tdx.windows()[0].AXChildren[1].AXChildren[4].AXValue != 'c成都顺城大街(原人民中路)':272 _tdx.windows()[0].AXChildren[1].AXChildren[4].setString('AXValue', 'c成都顺城大街(原人民中路)')273 _tdx.windows()[0].AXChildren[1].AXChildren[4].AXChildren[0].Press()274 time.sleep(0.3)275 _click(_tdx.windows()[0].AXChildren[1].AXChildren[4].AXChildren[1].AXChildren[0].AXChildren[25])276 time.sleep(0.2)277 _tdx.windows()[0].AXChildren[1].AXChildren[6].setString('AXValue', account)278 _tdx.windows()[0].AXChildren[1].AXChildren[9].setString('AXValue', password)279 time.sleep(0.1)280 _tdx.windows()[0].AXChildren[1].AXChildren[13].Press()281 # logger.debug('will waiting for login button enabled')282 try:283 while not _tdx.windows()[0].AXChildren[1].AXChildren[13].AXEnabled:284 time.sleep(1)285 _confirmIfMessage()286 except:287 pass288 except:289 pass290 # logger.debug('exception at _loginFirstIfUnlogin', exc_info=True)291def _loginFirstIfLocked(password):292 global _tdx293 try:294 lock_text = []295 try:296 lock_text = _tdx.windows()[0].staticTextsR('交易界面已锁定*')297 except:298 pass299 if len(lock_text) > 0:300 if password is None or len(password) < 6:301 _loginFirstIfLocked.passwordFlag = True302 raise Exception('You must assgin correct trade password for login!')303 else:304 return305 text_password = _tdx.windows()[0].textFields()[0]306 if text_password.AXSubrole == 'AXSecureTextField':307 text_password.setString('AXValue', password)308 _tdx.windows()[0].buttonsR('确定')[0].Press()309 time.sleep(0.1)310 except Exception as ex:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful