def post(self, image, caption, hashtags): self.driver.find_element_by_xpath( '//div[contains(@class, "q02Nz _0TPg")]').click() # click new post # go to the popped up open browser to select the image handle = "[CLASS:#32770; TITLE:Open]" autoit.win_wait(handle, 60) sleep(1) autoit.control_set_text(handle, "Edit1", '{}\{}'.format(images_path, image)) sleep(2) autoit.control_click(handle, "Button1") sleep(2) # expand the image self.driver.find_element_by_xpath( '//button[contains(@class, "pHnkA")]').click() sleep(2) # click next self.driver.find_element_by_xpath( "//button[contains(text(),'Next')]").click() sleep(3) # add caption self.driver.find_element_by_xpath( '//*[@id="react-root"]/section/div[2]/section[1]/div[1]/textarea' ).click() self.driver.find_element_by_xpath( '//*[@id="react-root"]/section/div[2]/section[1]/div[1]/textarea' ).send_keys('{}\n\n{}'.format(caption, ' '.join(hashtags))) sleep(2) # click share button self.driver.find_element_by_xpath( '//button[contains(text(), "Share")]').click()
def test_pcLogin(self): fp = webdriver.FirefoxProfile(r"C:\Users\mhf\AppData\Roaming\Mozilla\Firefox\Profiles\cv6txwo2.default") driver = webdriver.Firefox(fp) # driver = webdriver.Firefox () driver.get ("https://www.hongkunjinfu.com") WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login'))) driver.find_element_by_id ('login').send_keys ('14510000051') driver.find_element_by_xpath("html/body/div[2]/div[2]/div/ul/li[1]/a").click() autoit.win_activate('鸿坤金服——社区金融超市 - Mozilla Firefox') print("1111") autoit.send('{LCTRL down}'+'{LSHIFT down}'+'{! down}') # autoit.send('{LCTRL down}' + '{LALT down}' + '{a down}') # driver.find_element_by_id('login').send_keys(Keys.CONTROL + Keys.SHIFT + '!') time.sleep(2) autoit.win_wait('截取的图片另存为...') print("2222") autoit.control_focus('截取的图片另存为...','1001') print("3333") autoit.win_wait("[Class:#32770]",10) t = datetime.now().strftime('%Y%m%d%H%M%S') name='金服首页'+t # autoit.control_set_text('截取的图片另存为...','Edit1','金服网页102') autoit.control_set_text('截取的图片另存为...','Edit1',name) autoit.control_click('截取的图片另存为...','Button2') driver.close()
def _cancel_all(self): ret_code = -1 ret_value = tools.get_timestamp() error_msg = '' try: autoit.win_activate(self.wid_main) self.clean_dlg() autoit.control_click(self.wid_main, self.cid_cancel_refresh) autoit.control_click(self.wid_main, self.cid_cancel_refresh) ret_code = 1 time.sleep(5) autoit.control_click(self.wid_main, self.cid_cancel_selectall) ret_code = 2 time.sleep(0.5) autoit.control_click(self.wid_main, self.cid_cancel_do) ret_code = 3 if autoit.win_wait(self.wid_prompt, timeout=5) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 4 if autoit.win_wait(self.wid_prompt, timeout=20) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 0 except: error_msg = traceback.format_exc() return (ret_code, ret_value, error_msg, self.local_log_path) #==================================================================
def test_pcLogin(self): fp = webdriver.FirefoxProfile(r"C:\Users\mhf\AppData\Roaming\Mozilla\Firefox\Profiles\cv6txwo2.default") driver = webdriver.Firefox(fp) # driver = webdriver.Firefox () driver.get ("https://www.hongkunjinfu.com") WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login'))) driver.find_element_by_id ('login').send_keys ('14510000051') #保存网页弹出框 driver.find_element_by_id('login').send_keys(Keys.CONTROL+'s') time.sleep(2) # autoit.run("notepad.exe") # autoit.win_wait_active("[CLASS:Notepad]", 3) # autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}") # autoit.win_close("[CLASS:Notepad]") # autoit.control_click("[Class:#32770]", "Button2") # autoit.win_wait # autoit.win_wait_active("[CLASS:#32770]",3) autoit.win_activate('另存为') print("111111") autoit.control_focus('另存为','1001') print("22222222") autoit.win_wait("[Class:#32770]",10) autoit.control_set_text('另存为','Edit1','金服网页2') # autoit.control_send("[CLASS:#32770]", "Edit1", "hello world{!}") # autoit.control_click("[CLASS:#32770]", "Button2") autoit.control_click('另存为','Button2') driver.close()
def launch_power_express(self, version, syex_env, username): autoit.process_close('PowerExpress.exe') express_path = self.get_power_express_path(version) autoit.run(express_path + ' ENV:' + syex_env + ' testuser:'******'') autoit.win_wait(title='Power Express') BuiltIn().set_test_variable('${username}', username) BuiltIn().set_suite_variable('${syex_env}', syex_env)
def file_upload(window_name, file_name): autoit.win_wait(window_name, 30) if not autoit.win_exists(window_name): raise Exception("No File Upload Window is found") else: autoit.win_activate(window_name) autoit.control_focus(window_name, "[ID:1148]") autoit.control_set_text(window_name, "[ID:1148]", file_name) autoit.control_click(window_name, "[ID:1]")
def get_team_index_value(self, team): autoit.win_wait('[REGEXPTITLE:lection|Teamauswahl]') autoit.win_activate('[REGEXPTITLE:lection|Teamauswahl]') team_selection_list = self._create_power_express_app_instance().ListBox team_list = team_selection_list.ItemTexts() if team in team_list: return team_list.index(team) else: BuiltIn().fail("Team '" + team + "' is not found on team list")
def download_image(self): self.button_choose = self.find.element_by_xpath(lk_conf.button_choose_xpath).click() sleep(1) autoit.win_wait(lk_conf.autoit_title, lk_conf.autoit_wait) autoit.control_focus(lk_conf.autoit_title, lk_conf.autoit_control_edit) autoit.control_send(lk_conf.autoit_title, lk_conf.autoit_control_edit, lk_conf.autoit_image_path) autoit.control_click(lk_conf.autoit_title, lk_conf.autoit_control_button) self.find.element_by_xpath(lk_conf.button_download_xpath).click() sleep(3)
def main(): bot = Bot() print bot.title autoit.win_wait(bot.title, 5) counter = 0 poitonUse = 0 cycle = True summAttackCount = 0 while cycle: hpstatus = bot.checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(bot.title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 res = bot.findHP(); print 'tgs ' + str(res) if res > 0: autoit.control_send(bot.title, '', '{F1}', 0) bot.sleep(0.1,0.6) autoit.control_send(bot.title, '', '{F2}', 0) counter = 0 if res == 1: bot.sleep(0.3,0.6) if res > 1: if summAttackCount < 3: autoit.control_send(bot.title, '', '{F2}', 0) bot.sleep(1,3) summAttackCount += 1 # autoit.control_send(bot.title, '', '{F5}', 0) else: autoit.control_send(bot.title, '', '{F5}', 0) if counter < 3: autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1,0.2) autoit.control_send(bot.title, '', '{F1}', 0) if counter > 1: # bot.findTarget() autoit.control_send(bot.title, '', '{F7}', 0) if counter > 2: autoit.control_send(bot.title, '', '{F8}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def write_notepad(text): command('notepad.exe') try: autoit.win_wait('[CLASS:Notepad]', timeout=3) autoit.win_activate('[CLASS:Notepad]') except autoit.autoit.AutoItError as e: print(e) for i in text.split('*'): autoit.send(i) autoit.send('{enter}')
def main(): bot = Bot() autoit.win_wait(bot.title, 5) counter = 0 poitonUse = 0 cycle = True fullCounter = 0 while cycle: hpstatus = bot.checkOwnHp() mpstatus = bot.checkOwnMp() print 'hp ' + str(hpstatus) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', bot.getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if hpstatus == 1: autoit.control_send(bot.title, '', '{F5}', 0) print 'mp ' + str(mpstatus) if mpstatus < 2: autoit.control_send(bot.title, '', '{F11}', 0) res = bot.findHP() print 'tgs ' + str(res) if res == 3: fullCounter += 1 print 'fc ' + str(fullCounter) else: fullCounter = 0 if fullCounter > 9: autoit.control_send(bot.title, '', '{ESC}', 0) bot.sleep(0.3, 0.6) # autoit.control_send(bot.title, '', '{F3}', 0) # bot.mouseRotate() fullCounter = 0 if res > 0: autoit.control_send(bot.title, '', '{F1}', 0) counter = 0 bot.sleep(0.1, 0.2) autoit.control_send(bot.title, '', '{F2}', 0) else: fullCounter = 0 autoit.control_send(bot.title, '', '{F9}', 0) if counter < 2: autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1, 0.2) autoit.control_send(bot.title, '', '{F1}', 0) if counter > 1: # bot.findTarget() autoit.control_send(bot.title, '', '{F7}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def main(): bot = Bot() autoit.win_wait(bot.title, 5) counter = 0 poitonUse = 0 cycle = True fullCounter = 0 while cycle: hpstatus = bot.checkOwnHp() mpstatus = bot.checkOwnMp() print 'hp ' + str(hpstatus) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',bot.getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: autoit.control_send(bot.title, '', '{F5}', 0) print 'mp ' + str(mpstatus) if mpstatus < 2: autoit.control_send(bot.title, '', '{F11}', 0) res = bot.findHP(); print 'tgs ' + str(res) if res == 3: fullCounter += 1 print 'fc ' + str(fullCounter) else: fullCounter = 0 if fullCounter > 9: autoit.control_send(bot.title, '', '{ESC}', 0) bot.sleep(0.3,0.6) # autoit.control_send(bot.title, '', '{F3}', 0) # bot.mouseRotate() fullCounter = 0 if res > 0: autoit.control_send(bot.title, '', '{F1}', 0) counter = 0 bot.sleep(0.1,0.2) autoit.control_send(bot.title, '', '{F2}', 0) else: fullCounter = 0 autoit.control_send(bot.title, '', '{F9}', 0) if counter < 2: autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1,0.2) autoit.control_send(bot.title, '', '{F1}', 0) if counter > 1: # bot.findTarget() autoit.control_send(bot.title, '', '{F7}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def uplode_demo(): driver.get("http://ui.yansl.com/#/upload") sleep(2) #file = driver.find_element_by_xpath("//(//span[text()='点击上传'])[1]") #file.send_keys("D:\\1.png") file = driver.find_element_by_xpath("(// span[text() = '点击上传'])[1]") file.click() autoit.win_wait("打开",10) sleep(2) # autoit.control_send("打开", "Edit1", os.path.abspath(file_path)) autoit.control_set_text("打开", "Edit1","D:\\1.png") autoit.control_click("打开", "Button1")
def log_in(user): os.system('taskkill /f /im Steam.exe') os.system('start "" "C:\Program Files (x86)\Steam\Steam.exe" -login {} {}'.format( batch_sanitized(user.get_username()), batch_sanitized(user.get_password()) )) if user.get_shared_secret() is not None: autoit.win_wait("Steam Guard") autoit.win_activate("Steam Guard") autoit.win_wait_active("Steam Guard") autoit.send(generate_auth_code(user.get_shared_secret())) autoit.send('{ENTER}')
def main(): autoit.win_wait(title, 5) counter = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx, leftCornery, x2, y2) res = findHP(img) print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 if res == 1: sleep(0.3, 0.6) if res > 1: sleep(2, 4) else: if counter < 2: autoit.control_send(title, '', '{F3}', 0) sleep(0.1, 0.2) autoit.control_send(title, '', '{F1}', 0) if counter > 1: findTarget() # autoit.control_send(title, '', '{F11}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def test_upload2(driver): driver.get("http://ui.yansl.com/#/upload") sleep(2) file = driver.find_element_by_xpath('//*[@id="form"]/form/div[2]/div/div/div[1]/button/span') file.click() sleep(3) autoit.win_wait("打开", 10) sleep(1) # autoit.control_send("打开", "Edit1", os.path.abspath(file_path)) autoit.control_set_text("打开", "Edit1", "D:\\softwareback\\eval.png") sleep(5) autoit.control_click("打开", "Button1") sleep(10)
def main(): bot = Bot() print bot.title autoit.win_wait(bot.title, 5) bot.sleep(5,10) autoit.control_send(bot.title, '', 'oyajirospoil', 30) bot.sleep(7,10) autoit.control_send(bot.title, '', '8w141qtf', 30) bot.sleep(7,10) autoit.control_send(bot.title, '', '{NUMPADENTER}', 30) bot.sleep(7,10) autoit.control_send(bot.title, '', '{NUMPADENTER}', 30) pass
def login(window_name, username, password): print "Waiting for window with name: " + window_name autoit.win_wait(window_name, 30) if not autoit.win_exists(window_name): raise Exception("No Browser Login Window is found") else: print "Activating window" autoit.win_activate(window_name) sleep(1) print "Sending username & password" autoit.send(username) autoit.send("{tab}") autoit.send(password) autoit.send("{enter}")
def main(): autoit.win_wait(title, 5) counter = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 if res == 1: sleep(0.3,0.6) if res > 1: sleep(2,4) else: if counter < 2: autoit.control_send(title, '', '{F3}', 0) sleep(0.1,0.2) autoit.control_send(title, '', '{F1}', 0) if counter > 1: findTarget() # autoit.control_send(title, '', '{F11}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def file_upload(self, step, xpath, file_path): ''' 上传文件 :param step: 操作步骤 :param xpath: 文件上传按钮xpath :param file_path: 文件路径 :return: ''' self.local_element(xpath).click() autoit.win_wait("打开", 10) sleep(1) # autoit.control_send("打开", "Edit1", os.path.abspath(file_path)) autoit.control_set_text("打开", "Edit1", os.path.abspath(file_path)) autoit.control_click("打开", "Button1")
def file_upload(self, locator, file_path): ''' 点击上传文件按钮并上传文件 :param locator: 定位语句 例如:xpath=>//*[@id='kw'] :param file_path: 文件路径 :return: ''' self.click(locator) autoit.win_wait("打开", 10) self.sleep(1) file_path = os.path.abspath(file_path) self.shot("上传文件", file_path) # autoit.control_send("打开", "Edit1", os.path.abspath(file_path)) autoit.control_set_text("打开", "Edit1", file_path) autoit.control_click("打开", "Button1")
def main(): bot = Bot() wincount = sys.argv[1] autoit.win_wait(bot.title, 5) counter = 0 cycle = True while cycle: print 'send' for count in range(1, int(wincount) + 1): title = "[TITLE:Lineage II; INSTANCE:" + str(count) + "]" autoit.control_send(title, '', '{F1}', 0) bot.sleep(0.1, 0.3) autoit.control_send(title, '', '{F1}', 0) bot.sleep(0.7, 1.3) print 'title ', title bot.sleep(0.3, 0.8)
def upload_demo(): driver.get("http://ui.yansl.com/#/upload") sleep(1) # upload1 = driver.find_element_by_xpath("//label[text()='原始上传']/../div/input") # upload1.send_keys("C:\\Users\\Administrator\\Desktop\\replay_pid728.log") # 每个斜杠都要加\转义 # send_key 上传方法只支持input标签,type属性为file的 file=driver.find_element_by_xpath("(//span[text()='点击上传'])[1]") file.click() autoit.win_wait("打开", 10) sleep(2) # autoit.control_send("打开", "Edit1", os.path.abspath(file_path)) autoit.control_set_text("打开", "Edit1","C:\\Users\\Administrator\\Desktop\\replay_pid728.log" ) sleep(2) autoit.control_click("打开", "Button1")
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True sleep(3,3) while cycle: autoit.mouse_click('right', 768, 804) sleep(0.1,0.2) counter += 1 if counter > 861: cycle = False print counter if counter % 100 == 0: sleep(3,5) pass
def main(): bot = Bot() wincount = sys.argv[1] autoit.win_wait(bot.title, 5) counter = 0 cycle = True while cycle: print 'send' for count in range(1, int(wincount)+1): title = "[TITLE:Lineage II; INSTANCE:" + str(count) + "]" autoit.control_send(title, '', '{F1}', 0) bot.sleep(0.1,0.3) autoit.control_send(title, '', '{F1}', 0) bot.sleep(0.7,1.3) print 'title ', title bot.sleep(0.3,0.8)
def wait(self, timeout=5): ''' :description 暂停脚本的执行直至指定窗口存在(出现)为止. timeout 单位为秒. :return PID:成功, 0:失败(超时). ''' return autoit.win_wait(self.title, timeout, text=self.text)
def find_native_window(self, window_name, timeout=5): """ Wait for a native window to become visible Example: | Wait for Native Window | Calculator | """ logger.debug("Waiting {0}s for native window '{1}'".format( timeout, window_name)) try: autoit.win_wait(window_name, timeout) except autoit.AutoItError: logger.warn("Can't find native window!") return None hwnd = autoit.win_get_handle(window_name) logger.debug("Found native window '{0}'. Handle is {1}".format( window_name, hwnd)) return hwnd
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True sleep(3, 3) while cycle: autoit.mouse_click('right', 768, 804) sleep(0.1, 0.2) counter += 1 if counter > 861: cycle = False print counter if counter % 100 == 0: sleep(3, 5) pass
def main(): autoit.win_wait(title, 5) counter = 0 splcnt = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx, leftCornery, x2, y2) res = findHP(img) print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 sleep(2, 4) else: if counter < 1: autoit.control_send(title, '', '{F3}', 0) counter += 1 else: autoit.mouse_click('left', px, py1) sleep(0.5, 1.5) autoit.control_send(title, '', '{F4}', 0) counter = 0 pass
def _entrust_0(self, direction, code, price, volume): ret_code = -1 ret_value = tools.get_timestamp() error_msg = '' if direction == 'b': cid_code = self.cid_buy_code cid_price = self.cid_buy_price cid_volume = self.cid_buy_volume cid_able = self.cid_buy_able cid_entrust = self.cid_buy_entrust wait_flag = True elif direction == 's': cid_code = self.cid_sell_code cid_price = self.cid_sell_price cid_volume = self.cid_sell_volume cid_able = self.cid_sell_able cid_entrust = self.cid_sell_entrust wait_flag = False else: error_msg = 'unexpected direction' return (ret_code, ret_value, error_msg, self.local_log_path) ret_code = 1 try: autoit.win_activate(self.wid_main) self.clean_dlg() autoit.control_set_text(self.wid_main, cid_code, code) if wait_flag: for count in range(30): if autoit.control_get_text(self.wid_main, cid_able) != '': ret_code = 2 break else: time.sleep(0.1) if ret_code != 2: error_msg = 'code response timeout' return (ret_code, ret_value, error_msg, self.local_log_path) ret_code = 3 autoit.control_set_text(self.wid_main, cid_price, price) autoit.control_set_text(self.wid_main, cid_volume, volume) #autoit.win_activate(self.wid_main) autoit.control_click(self.wid_main, cid_entrust) ret_code = 4 if autoit.win_wait(self.wid_prompt, timeout=3) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 0 except autoit.AutoItError: error_msg = traceback.format_exc() return (ret_code, ret_value, error_msg, self.local_log_path)
def set_profile_picture(self): print("Setting profile picture...") try: picture_icon = self.driver.find_element_by_xpath("//button[@title='Add a profile photo']") picture_icon.click() #Selects a random picture from the "profile_images" folder image_path = os.path.dirname(os.path.realpath(__file__)) + "\profile_images\\128_%03d.jpg\\" % random.randint(1,73) #Handles the native file upload window interaction handle = "[CLASS:#32770; TITLE:Open]" autoit.win_wait(handle, 60) autoit.control_set_text(handle, "Edit1", image_path) autoit.control_click(handle, "Button1") except: print(" Account already has a profile picture")
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True while cycle: hpstatus = checkOwnHp() mpstatus = checkOwnMp() print 'hps ' + str(hpstatus) print 'mps ' + str(mpstatus) if mpstatus == 1: autoit.control_send(title, '', '{F11}', 0) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) # autoit.win_kill(title) cycle = False if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if hpstatus == 1: autoit.control_send(title, '', '{F5}', 0) img = getScreen(leftCornerx, leftCornery, x2, y2) res = findHP(img) print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 else: if counter == 0: autoit.control_send(title, '', '{F3}', 0) sleep(0.1, 0.3) autoit.control_send(title, '', '{F1}', 0) counter += 1 if counter >= 1: findTarget() # autoit.control_send(title, '', '{F11}', 0) counter = 0 print 'cnt ' + str(counter) pass
def post(self): self.driver.find_element_by_xpath(self.post_button).click() sleep(3) # autoit for uploading pics from local dir handle = "[CLASS:#32770; TITLE:Open]" autoit.win_wait(handle, 3) autoit.control_set_text( handle, "Edit1", fr"C:\Users\Alex\Desktop\mattbotpics\{self.rand_pic()}.jpg") autoit.control_click(handle, "Button1") self.driver.find_element(By.XPATH, self.next_btn).click() # gets random quote from the 'post' list of quotes self.driver.find_element(By.XPATH, self.desc_box).send_keys(rand_quote("post")) self.driver.find_element(By.XPATH, self.share_btn).click() # sleep to allow time to upload post sleep(15)
def main(): autoit.win_wait(title, 5) counter = 0 splcnt = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 sleep(2,4) else: if counter < 1: autoit.control_send(title, '', '{F3}', 0) counter += 1 else: autoit.mouse_click('left', px, py1) sleep(0.5,1.5) autoit.control_send(title, '', '{F4}', 0) counter = 0 pass
def post(self, image_path, label): WebDriverWait(self._driver, 10).until( EC.presence_of_element_located( (By.CSS_SELECTOR, 'svg[aria-label="New Post"]'))) ActionChains(self._driver).move_to_element( self._driver.find_element_by_css_selector( 'svg[aria-label="New Post"]')).click().perform() handle = "[CLASS:#32770; TITLE:Open]" autoit.win_wait(handle, 60) autoit.control_set_text(handle, "Edit1", image_path) autoit.control_click(handle, "Button1") button_expand = WebDriverWait(self._driver, 10).until( EC.presence_of_element_located( (By.XPATH, '//span[text()="Expand"]'))) button_expand.click() button_next = WebDriverWait(self._driver, 10).until( EC.presence_of_element_located( (By.XPATH, '//button[text()="Next"]'))) button_next.click() textarea_caption = WebDriverWait(self._driver, 10).until( EC.presence_of_element_located( (By.CSS_SELECTOR, 'textarea[aria-label="Write a caption…"]'))) textarea_caption.send_keys(label) button_share = self._driver.find_element_by_xpath( '//button[text()="Share"]') button_share.click() self._posted_count += 1 # button_not_now = WebDriverWait(self._driver, 10).until( # lambda x: # x.find_element_by_xpath('//button[text()="Not Now"]') or # x.find_element_by_css_selector('svg[aria-label="New Post"]') # ) if self._posted_count == 1: button_not_now = WebDriverWait(self._driver, 10).until( # lambda x: x.find_element_by_xpath('//button[text()="Not Now"] | //svg[@aria-label="New Post"]') lambda x: x.find_element_by_xpath('//button[text()="Not Now"]') ) if button_not_now.text == 'Not Now': button_not_now.click()
def select_profile(self, user_profile): autoit.win_wait('[REGEXPTITLE:rofil]') autoit.win_activate('[REGEXPTITLE:rofil]') select_profile_app = Application().Connect(path='PowerExpress.exe') select_profile_window = select_profile_app.window_(title_re=u'.*rofil') # select_profile_window = select_profile_app.top_window_() select_profile_window_list_box = select_profile_window.ListBox select_profile_window_list_box.Select(user_profile) select_profile_ok_button = select_profile_window.OK select_profile_ok_button.Click() BuiltIn().set_suite_variable('${user_profile}', user_profile) time.sleep(2) try: if autoit.control_command('Power Express', '[NAME:YesBtn]', 'IsVisible'): autoit.control_click('Power Express', '[NAME:YesBtn]') except Exception: pass
def main(): autoit.win_wait(title, 5) cycle = True while cycle: cpstatus = checkOwnCp() hpstatus = checkOwnHp() print 'cp ' + str(cpstatus) print 'hp ' + str(hpstatus) if cpstatus == 0: if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if cpstatus < 2: if hpstatus > 0: autoit.control_send(title, '', '{F8}', 0) sleep(0.8,1.5) pass
def main(): autoit.win_wait(title, 5) counter = 0 cycle = True while cycle: hpstatus = checkOwnHp() mpstatus = checkOwnMp() print 'hps ' + str(hpstatus) print 'mps ' + str(mpstatus) if mpstatus == 1: autoit.control_send(title, '', '{F11}', 0) if hpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) # autoit.win_kill(title) cycle = False if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: autoit.control_send(title, '', '{F5}', 0) img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 else: if counter == 0: autoit.control_send(title, '', '{F3}', 0) sleep(0.1,0.3) autoit.control_send(title, '', '{F1}', 0) counter += 1 if counter >= 1: findTarget() # autoit.control_send(title, '', '{F11}', 0) counter = 0 print 'cnt ' + str(counter) pass
def openOutputMovie(self, outputFile): ''' Opens the output movie file with the installed player using autoit :param outputFile: Output movie file ''' videoPlayerDir = self.getVideoPlayer() if videoPlayerDir == '': return self.pLabel.setText('Opening Movie %s' % outputFile.split('/')[-1]) title = outputFile.split('/')[-1].split('.')[0] outputFile = outputFile.replace('/','\\') autoit.run('%s %s' % (videoPlayerDir, outputFile)) if 'QuickTime' in videoPlayerDir: autoit.win_wait(title, 100) import time # This is a hack. We wait 3 sec for the movie to load completely before sending the next signal. # Otherwise the signal is not registered. time.sleep(1) autoit.control_send(title, '', '{CTRLDOWN}0{CTRLUP}')
def main(): autoit.win_wait(title, 5) cycle = True while cycle: cpstatus = checkOwnCp() hpstatus = checkOwnHp() print 'cp ' + str(cpstatus) print 'hp ' + str(hpstatus) if cpstatus == 0: if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png', getScreen(leftCornerx, leftCornery, x2, fullY2)) cycle = False if cpstatus < 2: if hpstatus > 0: autoit.control_send(title, '', '{F8}', 0) sleep(0.8, 1.5) pass
def main(): title = "[CLASS:l2UnrealWWindowsViewportWindow]" autoit.win_wait(title, 5) counter = 0 while True: img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print res if res > 0: autoit.control_send(title, '', '{F1}', 0) time.sleep(2) else: if counter == 1: autoit.control_send(title, '', '{F3}', 0) if counter > 2: findTarget(img) counter = 0 counter += 1 print 'counter ' + str(counter) pass
def add_photo(image_path): """ Метод добавляет фото по указанному пути :param image_path: - абсолютный путь до фото :return: """ import autoit title = "[CLASS:#32770]" control = '[CLASS:Edit; INSTANCE:1]' control_open_btn = '[CLASS:Button; INSTANCE:1]' opened = autoit.win_wait(title, 5) if opened != 1: msg = "Not opened window!" service_log.error(msg) assert msg handle = autoit.win_get_handle(title) if isinstance(handle, int) is not True: msg = "Not found Handle!" service_log.error(msg) assert msg autoit.win_activate_by_handle(handle) ret = autoit.control_focus(title, control) if ret != 1: msg = "Not found control_focus!" service_log.error(msg) assert msg time.sleep(1) autoit.control_set_text(title, control, image_path) autoit.control_focus(title, control_open_btn) autoit.control_click(title, control_open_btn) #autoit.mouse_click() #ENTER - подтверждение (можно вместо этого нажать на кнопку) #autoit.send("{ENTER}") time.sleep(5) return True
def main(): autoit.win_wait(title, 5) counter = 0 splcnt = 0 poitonUse = 0 cycle = True while cycle: hpstatus = checkOwnHp() cpstatus = checkOwnCp() print 'hps ' + str(hpstatus) print 'cps ' + str(cpstatus) if cpstatus < 3: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False continue # autoit.win_kill(title) if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 if hpstatus == -1: autoit.control_send(title, '', '{F9}', 0) sleep(6,10) restoreMenyHp() autoit.control_send(title, '', '{F9}', 0) img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: if res > 2 and splcnt < 4: autoit.control_send(title, '', '{F2}', 0) sleep(1,3) splcnt += 1 else: autoit.control_send(title, '', '{F1}', 0) if (res > 1): sleep(2,4) else: sleep(0.5, 1) counter = 0 else: splcnt = 0 if res == 0: autoit.control_send(title, '', '{F4}', 0) sleep(0.2,0.7) if counter < 2: autoit.control_send(title, '', '{F3}', 0) if res == 0 and counter == 0: sleep(0.1,0.3) autoit.control_send(title, '', '{F2}', 0) if counter > 1: findTarget() # autoit.control_send(title, '', '{F11}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def main(): bot = Bot() autoit.win_wait(bot.title, 5) counter = 0 poitonUse = 0 cycle = True fullCounter = 0 while cycle: hpstatus = bot.checkOwnHp() print 'hp ' + str(hpstatus) if hpstatus == 0: bot.sleep(2,3) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',bot.getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(bot.title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 res = bot.findHP(); print 'tgs ' + str(res) if res == 3: fullCounter += 1 print 'fc ' + str(fullCounter) else: fullCounter = 0 lure = 0 if fullCounter > 6: autoit.control_send(bot.title, '', '{ESC}', 0) bot.sleep(0.3,0.6) autoit.control_send(bot.title, '', '{F3}', 0) # bot.mouseRotate() fullCounter = 0 if res > 0: autoit.control_send(bot.title, '', '{F1}', 0) counter = 0 if res == 1 or res == 3: bot.sleep(0.3,0.6) if res > 1 and res < 3: bot.sleep(1,3) else: fullCounter = 0 if counter < 2: autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1,0.2) autoit.control_send(bot.title, '', '{F1}', 0) if counter > 1: # bot.findTarget() print 'counrter > 1' autoit.control_send(bot.title, '', '{F7}', 0) bot.sleep(0.3,0.5) if bot.findHP() > 0 : print 'lure' autoit.control_send(bot.title, '', '{F5}', 0) bot.sleep(5,7) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def main(): autoit.win_wait(title, 5) counter = 0 poitonUse = 0 cycle = True fightCounter = 0 rage = 0 while cycle: cpstatus = checkOwnCp() hpstatus = checkOwnHp() print 'hp ' + str(hpstatus) if cpstatus == -1: print 'CPDamage' cv2.imwrite('CPDamage' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False # autoit.win_kill(title) if hpstatus == 0: print 'Dead' cv2.imwrite('Dead' + str(int(time.time())) + '.png',getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 if (not matchBuff('template_rage.png',360,80)): if (rage == 0): autoit.mouse_click('left', 1485, 885) sleep(0.1,0.3) rage += 1 autoit.control_send(title, '', '{F1}', 0) if (rage > 5): rage = 0 else: rage = 0 img = getScreen(leftCornerx,leftCornery,x2,y2) res = findHP(img); print 'tgs ' + str(res) if res > 0: autoit.control_send(title, '', '{F1}', 0) counter = 0 if res == 1: sleep(0.3,0.6) if res > 1: sleep(2,4) else: if counter < 2: autoit.control_send(title, '', '{F3}', 0) sleep(0.1,0.2) autoit.control_send(title, '', '{F1}', 0) if counter >= 2: # autoit.control_send(title, '', '{F11}', 0) # findTarget() autoit.control_send(title, '', '{F11}', 0) sleep(0.1,0.2) autoit.control_send(title, '', '{F3}', 0) # sleep(0.1,0.2) # autoit.control_send(title, '', '{F1}', 0) counter = 0 counter += 1 print 'cnt ' + str(counter) pass
def main(): user_dir = get_users_main_directory() check_lp_power_data_folder_exists(user_dir) check_database_file_exists(user_dir) trial = {} trial = prompt_setup(trial, user_dir) # stopgap for pre-class variables walk_speed = trial["Speed [MPH]"] walk_style = trial["Walk Style [Normal/LP]"] pack_number = trial["Pack Number [XXX]"] # MAKE FOLDERS FOR TRIAL BASED ON PREVIOUSLY-ENTERED INPUTS make_pack_folder(pack_number, walk_speed, walk_style, user_dir) print('.....') print("..........Launching.....") # SET UP BASIC AUTO-IT SETTINGS TO USE WINDOW-RELATIVE COORDINATES autoit.auto_it_set_option('MouseCoordMode', 0) autoit.auto_it_set_option('SendKeyDelay', 10) # OPEN PICOSCOPE USING OUR DEFAULT WINDOW LAYOUT WITH TWO PANELS AND POWER UP TOP default_pico = os.path.join(user_dir, "electrical_power.psdata") click_on_file(default_pico) # PREPARE TO RUN THE RECORD DATA MACRO autoit.win_wait('PicoScope 6 - [electrical_power.psdata]') autoit.win_activate('PicoScope 6 - [electrical_power.psdata]') time.sleep(0.5) autoit.send('{ALT}{TAB}{TAB}{TAB}{TAB}{ENTER}{END}{UP}{ENTER}') autoit.win_wait('Macro Recorder') autoit.control_click('Macro Recorder', "[Name:_buttonImport]") time.sleep(1) macro_text = os.path.abspath(os.path.join(user_dir, "record_20sec.psmacro")) autoit.clip_put(macro_text) autoit.win_wait("Open") autoit.send('^V', 0) autoit.send('{ENTER}') msgbox("Ready to go?") # RUN THE MACRO autoit.win_activate('Macro Recorder') autoit.win_wait('Macro Recorder') autoit.control_click('Macro Recorder', "[Name:_buttonExecute]") time.sleep(22) autoit.win_activate('Macro Recorder') autoit.send('{ESCAPE}') # BEGIN SAVING THE DATA i = datetime.now() save_text = os.path.abspath(os.path.join(user_dir, 'LP Power Data', "{}".format("LP-{0}".format(pack_number)), "{0}MPH-{1} Walk".format(walk_speed, walk_style), "{0}MPH-{1} Walk_".format(walk_speed, walk_style) + i.strftime('%Y-%m-%d %Hh%Mm%Ss')+ ".psdata")) autoit.clip_put(save_text) # SAVE ALL CAPTURED WAVEFORMS IN PICO FORMAT autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.send('{ALT}{f}{a}') time.sleep(.5) autoit.win_wait("Save As") autoit.control_send('Save As', "[Class:Edit;INSTANCE:1]", '^V', 0) autoit.send('{ENTER}') # BEGIN SAVE SEQUENCE FOR CSV FORMAT autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.mouse_click("primary", 433, 67, 2, 1) # MUST CLICK ON SECTION OF WINDOW CONTAINING POWER TRACE OR ALL AVERAGES CALCULATED WILL BE MESSED UP autoit.win_activate('PicoScope 6') autoit.win_wait("PicoScope 6") autoit.mouse_click("primary", 230, 260, 1, 0) # autoit.control_click('PicoScope 6', "[CLASS:WindowsForms10.Window.8.app.0.1114f81_r13_ad1; INSTANCE:55]") autoit.send('{ALT}{f}{a}') time.sleep(.5) autoit.win_wait("Save As") autoit.control_send('Save As', "[Class:Edit;INSTANCE:1]", '^V', 0) # SAVE ALL CAPTURED 5SEC INTERVALS autoit.control_click('Save As', "[CLASS:ComboBox;INSTANCE:3]") autoit.send("{HOME}{DOWN}{DOWN}{ENTER}") # autoit.control_click("Save As", "[NAME:_currentBufferRadio]") time.sleep(0.5) autoit.send('{ENTER}') time.sleep(4.5) autoit.process_close('PicoScope.exe') # BOTH SAVE OPERATIONS NOW COMPLETE. THERE IS A CSV FOR EACH 5SEC INTERVAL IN A NEW SUBDIRECTORY OF THIS TRIAL. print("") print("Sit tight, I'm still doing some thinking....") # UPDATE ALL CSV FILES TO BE XLSX AND CALCULATE THEIR 5SEC AVERAGES run_avgs = recursively_repair_all_csv_files(save_text, user_dir, walk_speed) # ADD ALL INFORMATION COLLECTED TO THE EXPERIMENTS SPREADSHEET patch_experiments_database(trial, run_avgs, user_dir) print("") # WRITE THE METADATA SETTINGS TO A FILE FOR FUTURE RECORD with open('{}'.format(save_text.replace(".psdata", ".LPmeta")), 'w') as outfile: json.dump(trial, outfile, indent=4, separators=(',', ': ')) print("") print("LP Metadata file successfully saved for the future with all info the state of the pack as you have just tested it.") print("") # print_average_power(dest_filename) print(".................................. Testing Complete.")
def main(): bot = Bot() print bot.title autoit.win_wait(bot.title, 5) counter = 0 poitonUse = 0 cycle = True spoilCount = 0 fullCounter = 0 deadCounter = 0 sweepcounter = 0 while cycle: hpstatus = bot.checkOwnHp() print 'hp ' + str(hpstatus) checkOwnMp() if hpstatus == 0: autoit.control_send(bot.title, '', '{F9}', 0) bot.sleep(0.3,0.6) print 'I\'m Dead', str(datetime.now()) str(datetime.now()) cv2.imwrite('Dead' + str(int(time.time())) + '.png',bot.getScreen(leftCornerx,leftCornery,x2,fullY2)) cycle = False if hpstatus == 1: if poitonUse == 0: autoit.control_send(bot.title, '', '{F10}', 0) poitonUse += 1 if poitonUse > 5: poitonUse = 0 else: poitonUse = 0 res = bot.findHP(); print 'tgs ' + str(res) if res == 3: fullCounter += 1 print 'fc ' + str(fullCounter) autoit.control_send(bot.title, '', '{F1}', 0) else: fullCounter = 0 if fullCounter > 6: autoit.control_send(bot.title, '', '{ESC}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1,0.3) # bot.mouseRotate() fullCounter = 0 spoilCount = 0 if res > 0: autoit.control_send(bot.title, '', '{F1}', 0) # autoit.control_send(bot.title, '', '{F2}', 0) if res < 3: counter = 0 sweepcounter = 0 deadCounter = 0 if res > 0 and spoilCount < 4: autoit.control_send(bot.title, '', '{F5}', 0) bot.sleep(0.2, 0.4) # autoit.control_send(bot.title, '', '{F4}', 0) if spoilCount < 5: autoit.control_send(bot.title, '', '{F2}', 0) bot.sleep(0.2, 0.4) autoit.control_send(bot.title, '', '{F2}', 0) bot.sleep(0.2, 0.4) autoit.control_send(bot.title, '', '{F6}', 0) # if spoilCount % 2 == 0: # autoit.control_send(bot.title, '', '{F2}', 0) # else: # autoit.control_send(bot.title, '', '{F6}', 0) bot.sleep(0.2, 0.4) autoit.control_send(bot.title, '', '{F1}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F1}', 0) spoilCount += 1 else: deadCounter += 1 spoilCount = 0 bot.sleep(0.1,0.2) if res == 0 and counter < 2 and sweepcounter < 3: autoit.control_send(bot.title, '', '{F4}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F4}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F4}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F4}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F3}', 0) print 'F4' deadCounter = 0 sweepcounter += 1 if counter < 3: autoit.control_send(bot.title, '', '{F3}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F1}', 0) print 'F3' if counter > 2: # bot.findTarget() autoit.control_send(bot.title, '', '{F7}', 0) bot.sleep(0.1,0.3) autoit.control_send(bot.title, '', '{F7}', 0) print 'F7' counter = 0 counter += 1 print 'cnt ' + str(counter) pass