import uiautomator2 import threading class JdClient: def __init__(self, device): self.device = device self.dev = uiautomator2.connect(device) def close_app(self): self.dev.app_stop('com.jingdong.app.mall') def set_clipboard(self, text): self.dev.set_clipboard(text) def open_app(self): self.dev.app_start('com.jingdong.app.mall') def open_and_click(self): self.dev.app_start('com.jingdong.app.mall') n = 30 while n > 0: if self.dev(text='跳过').exists: self.dev(text='跳过').click() break else: self.dev.implicitly_wait(0.1) n -= 1 while True: if self.dev(text='立即查看').exists: print(self.device, '点击立即查看') self.dev.implicitly_wait(1) self.dev(text='立即查看').click() break else: self.dev.implicitly_wait(1) # print('等待1秒') self.dev.implicitly_wait(2) # self.dev.click(531, 1323) # while True: #531,1323 # if self.dev(text='成功邀请10人助力赢好礼').exists: # print(self.device, '成功邀请10人助力赢好礼') # self.dev.implicitly_wait(1) # # self.dev(text='为好友助力').click() # self.dev.click(531, 1323) # break # else: # self.dev.implicitly_wait(1) # # print('等待1秒') n = 10 while n > 0: self.dev.click(531, 1323) self.dev.implicitly_wait(1) n -= 1 def full_steps(self, text): self.set_clipboard(text) self.open_and_click() if __name__ == '__main__': device_list = [ '127.0.0.1:16416', '127.0.0.1:16448', '127.0.0.1:16480', '127.0.0.1:16512', # '127.0.0.1:16544', # '127.0.0.1:16576', '127.0.0.1:16608', # '127.0.0.1:16640', # '127.0.0.1:16672', # '127.0.0.1:16704', # 'b189a9ab', # 一加 ] # device_list = ['127.0.0.1:16416', # '127.0.0.1:16448'] jd_client_list = [] for dev in device_list: jd_client = JdClient(dev) jd_client_list.append(jd_client) for jd_client in jd_client_list: t = threading.Thread(target=jd_client.close_app, args=()) t.start() for jd_client in jd_client_list: t = threading.Thread(target=jd_client.full_steps, args=('16:/¥FCWK99OZFKV¥ MU5104,⇥⤴ι🆖▾東【京东超市】分享助力赢玩具乐器五折券',)) t.start()