初识PC自动化,就在登录这里卡住了。以下两种方法,请问那种方法执行效率更高?
C仙人说是第二种。NO,第一种方法执行时间少了一半左右呢。请问是什么原因?还有执行效率更高的写法吗?求分享
方法1:
app = Application(backend="uia").connect(process=process_id)
window = app.window(title="登录到全部行情主站")
a=time.time()
children = window.descendants()
for child in children:
if child.element_info.automation_id == "1001":
child.set_focus()
child.set_edit_text(username)
if child.element_info.automation_id == "21812":
child.set_focus()
child.set_edit_text(password)
if child.element_info.name == "登 录":
child.click()
方法2:
app = Application(backend="uia").connect(process=process_id)
window = app.window(title="登录到全部行情主站")
#window.print_control_identifiers()
child=window.child_window(auto_id="21795", control_type="ComboBox")
child1=child.child_window(auto_id="1001", control_type="Edit")
child1.set_edit_text(username)
child2=window.child_window(auto_id="21812", control_type="Edit")
child2.set_edit_text(password)
child3=window.child_window(title="登 录", auto_id="1", control_type="Button")
child3.click()
以下是window的层级关系
Pane - '登录到全部行情主站' (L830, T441, R1730, B1086)
['登录到全部行情主站', 'Pane', '登录到全部行情主站Pane']
child_window(title="登录到全部行情主站", control_type="Pane")
|
| ComboBox - '' (L960, T798, R1335, B848)
| ['ComboBox打开', 'ComboBox', 'StaticComboBox']
| child_window(auto_id="21795", control_type="ComboBox")
| |
| | Edit - '' (L1008, T806, R1305, B841)
| | ['Edit', 'StaticEdit', 'Edit0', 'Edit1', 'StaticEdit0', 'StaticEdit1']
| | child_window(auto_id="1001", control_type="Edit")
| |
| | Button - '打开' (L1311, T800, R1334, B847)
| | ['打开Button', 'Button', '打开', 'Button0', 'Button1']
| | child_window(title="打开", auto_id="DropDown", control_type="Button")
|
| Edit - '' (L960, T855, R1335, B900)
| ['Edit2', 'StaticEdit2']
| child_window(auto_id="21812", control_type="Edit")
|
| Button - '保存密码' (L960, T914, R1080, B944)
| ['Button2', '保存密码Button', '保存密码']
| child_window(title="保存密码", auto_id="20329", control_type="Button")
|
| Button - '自动登录' (L1230, T914, R1350, B944)
| ['Button3', '自动登录', '自动登录Button']
| child_window(title="自动登录", auto_id="20330", control_type="Button")
|
| Static - '忘记账号/密码?' (L960, T1010, R1110, B1040)
| ['忘记账号/密码?', '忘记账号/密码?Static', 'Static', 'Static0', 'Static1']
| child_window(title="忘记账号/密码?", auto_id="21896", control_type="Text")
|
| Static - '脱机' (L1293, T1008, R1338, B1038)
| ['脱机Static', 'Static2', '脱机', '脱机0', '脱机1']
| child_window(title="脱机", auto_id="22384", control_type="Text")
|
| Button - '免费注册' (L1448, T824, R1628, B860)
| ['免费注册', 'Button4', '免费注册Button']
| child_window(title="免费注册", auto_id="21816", control_type="Button")
|
| Button - '脱机' (L1511, T998, R1547, B1034)
| ['Button5', '脱机Button', '脱机2', '脱机Button0', '脱机Button1']
| child_window(title="脱机", auto_id="21827", control_type="Button")
|
| Button - '脱机' (L1448, T998, R1484, B1034)
| ['Button6', '脱机Button2', '脱机3']
| child_window(title="脱机", auto_id="21853", control_type="Button")
|
| Button - '脱机' (L1574, T998, R1610, B1034)
| ['Button7', '脱机Button3', '脱机4']
| child_window(title="脱机", auto_id="21829", control_type="Button")
|
| Button - '游客登录' (L1448, T950, R1628, B986)
| ['Button8', '游客登录', '游客登录Button']
| child_window(title="游客登录", auto_id="21851", control_type="Button")
|
| Static - 'Static' (L831, T443, R1731, B754)
| ['StaticStatic', 'Static3']
| child_window(title="Static", auto_id="22069", control_type="Text")
|
| Static - '没有账号?您可以:' (L1448, T794, R1658, B821)
| ['没有账号?您可以:Static', '没有账号?您可以:', 'Static4']
| child_window(title="没有账号?您可以:", auto_id="21487", control_type="Text")
|
| Button - '设置' (L1218, T1011, R1278, B1041)
| ['设置', 'Button9', '设置Button']
| child_window(title="设置", auto_id="21898", control_type="Button")
|
| Button - '扫码登录' (L1448, T908, R1628, B944)
| ['扫码登录', '扫码登录Button', 'Button10']
| child_window(title="扫码登录", auto_id="63275", control_type="Button")
|
| Button - '短信登录' (L1448, T866, R1628, B902)
| ['Button11', '短信登录Button', '短信登录']
| child_window(title="短信登录", auto_id="63276", control_type="Button")
|
| Button - '登 录' (L960, T956, R1335, B1001)
| ['Button12', '登 录', '登 录Button']
| child_window(title="登 录", auto_id="1", control_type="Button")