def send_files(): global doc_filename # Attachment Drop Down Menu clipButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/div/span') clipButton.click() time.sleep(1) # To send a Document(PDF, Word file, PPT) docButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[3]/button' ) docButton.click() time.sleep(1) docPath = os.getcwd() + "\\Documents\\" + doc_filename autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (docPath)) autoit.control_click("Open", "Button1") time.sleep(3) whatsapp_send_button = browser.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span' ) whatsapp_send_button.click()
def send_attachment(image_path): try: # Attachment Drop Down Menu clipButton = driver.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/div/span') clipButton.click() time.sleep(1) # To send Videos and Images. mediaButton = driver.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button' ) mediaButton.click() time.sleep(3) autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (image_path)) autoit.control_click("Open", "Button1") time.sleep(6) whatsapp_send_button = driver.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span' ) whatsapp_send_button.click() except Exception as e: print(e)
def command_thor_test(command): try: ai.win_activate('[title:Control a Device]') except ai.AutoItError: print('AutoItError happened, returned') return time.sleep(0.1) ai.control_focus('[title:Control a Device]','Edit8') time.sleep(0.1) ai.control_set_text('[title:Control a Device]','Edit8',command) time.sleep(1) ai.control_click('[title:Control a Device]','Button15') #clear the command window time.sleep(0.5) ai.control_click('[title:Control a Device]','Button13') #send the command work time.sleep(2) ai.win_activate('[title:NetLinx Studio]') time.sleep(1) count = 0 while True: count+=1 print('try '+str(count)+' time') out = get_comeback_message() if out!='': print('congratulations! the output is not empty') break elif count<=3: time.sleep(3) else: print('even tried 4 times, the output is still empty') break return out #%% test the function #haha=command_thor_test('get status') #print(haha)
def file_upload_india(self): autoit.win_active("Open") autoit.control_set_text( "Open", "Edit1", r"C:\selenium_scripts\upload\AppointmentUpload_IND.xlsx") autoit.control_send("Open", "Edit1", "{ENTER}") time.sleep(2)
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 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_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 Desconto(Desc, Arred): log.EscreverLog('Função Desconto') Tecla.TempoR() autoit.control_click("[Class:TFRM_FINALVENDA]", "TRzNumericEdit4") Tecla.TempoR() log.EscreverLog('Desconto de: ' + str(Desc) + '%') autoit.control_set_text("[Class:TFRM_FINALVENDA]", "TRzNumericEdit4", Desc) Tecla.Enter() SENHAFUNC.SENHAFUNC() autoit.control_click("[Class:TFRM_FINALVENDA]", "TRzNumericEdit3") Tecla.TempoR() log.EscreverLog('Arredondamento de: ' + str(Arred) + 'R$') autoit.control_set_text("[Class:TFRM_FINALVENDA]", "TRzNumericEdit3", Arred) Tecla.Enter() try: log.EscreverLog('Alerta de Arredondamento') autoit.win_wait_active("[Class:TFRM_VSMTASKDIALOG]", Variaveis.TTela) Tecla.TempoR() autoit.control_click("[Class:TFRM_VSMTASKDIALOG]", "TRzBitBtn1") Tecla.TempoR() log.EscreverLog('Botão ok') log.EscreverLog('Clicou ok') except: log.EscreverLog('Não teve alerta de Arredondamento')
def SENHAFUNC(): try: log.EscreverLog('Entra Função SenhaFunc') try: Variaveis.Tempo = (0.25) log.EscreverLog('Tempo. ate ' + str(Variaveis.Tempo) + ' segundos') autoit.win_wait_active("[Class:TFRM_SENHAFUNC]", Variaveis.Tempo) Tela.Alerta('Acima do limite', 'Desconto aceito') log.EscreverLog('Pede Senha') Tempo.Dig() autoit.control_set_text("[Class:TFRM_SENHAFUNC]", "TRzButtonEdit1", Variaveis.SenhaAdmin) log.EscreverLog('Passa Senha') Tecla.Enter() log.EscreverLog('Senha Ok') except: Tecla.Enter() Variaveis.Tempo = (0.25) log.EscreverLog('Tempo. ate ' + str(Variaveis.Tempo) + ' segundos') autoit.win_wait_active("[Class:TFRM_SENHAFUNC]", Variaveis.Tempo) log.EscreverLog('Pede Senha') Tecla.TempoR() autoit.control_set_text("[Class:TFRM_SENHAFUNC]", "TRzButtonEdit1", Variaveis.SenhaAdmin) log.EscreverLog('Passa Senha') Tecla.Enter() log.EscreverLog('Senha Ok') except: log.EscreverLog('Sem Senha') log.EscreverLog('Sai Função SenhaFunc')
def send_attachment(): # Attachment Drop Down Menu clipButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/div/span') clipButton.click() time.sleep(1) # To send Videos and Images. mediaButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button' ) mediaButton.click() time.sleep(3) hour = datetime.datetime.now().hour # After 5am and before 11am scheduled this. if (hour >= 5 and hour <= 11): image_path = os.getcwd() + "\\Media\\" + 'goodmorning.jpg' # After 9pm and before 11pm schedule this elif (hour >= 21 and hour <= 23): image_path = os.getcwd() + "\\Media\\" + 'goodnight.jpg' else: # At any other time schedule this. image_path = os.getcwd() + "\\Media\\" + 'howareyou.jpg' # print(image_path) autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (image_path)) autoit.control_click("Open", "Button1") time.sleep(3) whatsapp_send_button = browser.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span' ) whatsapp_send_button.click()
def upload(self, filePath): xx = filePath[1:2] print(xx) if (filePath[1:2] != ':'): #是相对路径 要到files下面去找 pwd = os.getcwd() tmp = pwd.split("src")[0] tmp = os.path.abspath(tmp + os.path.sep + "..") + "\\files" filePath = filePath.replace("/", "\\") if (not filePath.startswith("\\")): filePath = "\\" + filePath filePath = tmp + filePath dirPath = os.path.dirname(filePath) if (not dirPath.endswith('\\')): dirPath = dirPath + '\\' l = len(dirPath) fileName = filePath[l:] #下面开始是在上传对话框上的操作 time.sleep(1) autoit.win_active("打开") autoit.control_set_text("打开", "Edit1", dirPath) time.sleep(0.5) autoit.control_click("打开", "Button1") time.sleep(3) autoit.control_set_text("打开", "Edit1", fileName) autoit.control_click("打开", "Button1")
def mail(): try: time.sleep(soft_wait) driver.find_element(By.XPATH, "//*[contains(text(), 'Email')]").click() time.sleep(long_wait) driver.find_element(By.XPATH, '//*[@class="ql-editor ql-blank"]').click() time.sleep(soft_wait) keyboard.write(message) time.sleep(soft_wait) # click on Add photo time.sleep(soft_wait) driver.find_element(By.XPATH, "//*[contains(text(), 'Add Photo')]").click() time.sleep(soft_wait) # enter the location of the image file you want send in next line autoit.control_set_text("Open", "Edit1", r"D:\ME\c dfrive\New folder\557421.jpg") autoit.control_send("Open", "Edit1", "{ENTER}") time.sleep(soft_wait) driver.find_element(By.XPATH, "//*[contains(text(), 'Send')]").click() time.sleep(long_wait) except: pass
def add_data_shp(): #加载矢量数据shp格式 autoit.mouse_click("left",120,92,1) #点击加载矢量数据 autoit.win_wait_active(u"打开矢量文件",15) autoit.control_set_text(u"打开矢量文件","Edit1",r"C:\Users\admin\Desktop\PIEDATA\Lambert_SHP\beijing.shp") autoit.control_click(u"打开矢量文件","Button1") #选择好文件,点击打开 autoit.win_wait_active(u"提示",5) #不同坐标系,提示是否新建图层 autoit.control_click(u"提示","Button2") #新建图层 sleep(5)
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 add_data_jpg(): #加载栅格数据jpg格式 '''添加数据方法一:设置焦点进行传参,添加jpg数据''' autoit.mouse_click("left",54,92,1) #点击加载栅格数据 autoit.win_wait_active(u"打开栅格文件",15) #等待窗口活跃,15秒超时 autoit.control_focus(u"打开栅格文件", "[Class:Edit; instance:1]") #设置焦点 autoit.control_set_text(u"打开栅格文件", "[Class:Edit; instance:1]","C:\Users\Administrator\Desktop\GF1.jpg") # 输入文本 autoit.control_click(u"打开栅格文件", "Button1") sleep(5)
def test_upload_file2(driver): file = driver.find_element_by_xpath( "//label[text()='点击上传']/..//div//span").click() sleep(3) autoit.control_set_text("打开", "Edit1", "C:\\Users\\admin\\Desktop\\hillway.png") sleep(3) autoit.control_click("打开", "Button1") pass
def handle_dialog(picName): attempts = 0 while attempts <= 5: try: autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open","Edit1",picName) autoit.control_send("Open","Edit1","{ENTER}") break except: sleep(.3)
def click_ac_upload(self, index, path): """ 单击上传按钮;通过索引来决定点击哪个上传功能 :param index: 索引为找到元素索引 :param path: 上传图片所在绝对路径 :return: """ self.click_btn_index('上传', index, *(self.activity_upload_locs)) #autoit处理 autoit.control_set_text('打开', '[Class:Edit; instance:1]', path) autoit.control_click('打开', '[Class:Button; INSTANCE:1]')
def add_data_tif(): # 加载栅格数据Tif格式,此格式是否需要建立金字塔 '''添加数据方法二:直接使用control_set_text传参,添加tif数据是否建立金字塔''' autoit.mouse_click("left", 50, 92, 1) # 点击加载栅格数据 autoit.win_wait_active(u"打开栅格文件", 15) autoit.control_set_text(u"打开栅格文件", "Edit1", r"C:\Users\admin\Desktop\PIEDATA\GF1.tiff") autoit.control_click(u"打开栅格文件", "Button1") # 确定打开文件 autoit.win_wait_active(u"建立金字塔", 5) # 等待是否建立金字塔窗口 autoit.control_click(u"建立金字塔", "Button3") # 取消建立金字塔 sleep(10) '''添加数据方法三:使用control_send传参,添加tif数据是否建立金字塔'''
def sendAttachment(): global imagename if imagename: if ',' not in imagename: # Attachment Drop Down Menu clipButton = browser.find_element_by_xpath( '//*[@id="main"]/footer/div[1]/div[1]/div[2]/div[1]/div[1]/span' ) clipButton.click() time.sleep(1) # To send Videos and Images. mediaButton = browser.find_element_by_xpath( '//*[@id="main"]/footer/div[1]/div[1]/div[2]/div[1]/span/div/div/ul/li[1]/button' ) mediaButton.click() time.sleep(3) imagePath = os.getcwd( ) + "\\AlWhatsApp\\Documents\\" + imagename autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (imagePath)) autoit.control_click("Open", "Button1") time.sleep(3) whatsapp_send_button = browser.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span' ) whatsapp_send_button.click() if ',' in imagename: imagename = imagename.split(',') for i in imagename: # Attachment Drop Down Menu clipButton = browser.find_element_by_xpath( '//*[@id="main"]/footer/div[1]/div[1]/div[2]/div[1]/div[1]/span' ) clipButton.click() time.sleep(1) # To send Videos and Images. mediaButton = browser.find_element_by_xpath( '//*[@id="main"]/footer/div[1]/div[1]/div[2]/div[1]/span/div/div/ul/li[1]/button' ) mediaButton.click() time.sleep(3) imagePath = os.getcwd( ) + "\\AlWhatsApp\\Documents\\" + i autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (imagePath)) autoit.control_click("Open", "Button1") time.sleep(3) whatsapp_send_button = browser.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span' ) whatsapp_send_button.click()
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 test_new_download(browser): driver = browser download_name = "1Test name" # Количесто записей в таблице. Можно и без базы через gui парсить. with allure.step(f'count downloads'): db_items_default = len(connect("SELECT * FROM oc_download")) with allure.step(f'login auth'): AuthPage(driver).login(username='******', password='******') with allure.step(f'go to Downloads page' ): # TODO Вынести переход до нужного блока в Base. DashboardPage(driver).navigate_to(dashboard_menu='Catalog', submenu='Downloads') with allure.step(f'go to Add download'): DownloadsPage(driver).goto_new_download_page() with allure.step(f'input download name'): DownloadsPage(driver).name_input_fill(download_name) # ActionChains(driver).move_to_element(download_name_input).click().send_keys(download_file_name).perform() with allure.step(f"Download file with autoIt"): DownloadsPage(driver).upload_btn_click() # TODO: уйти от autoit, потому что в headless режиме не заработает. # Для добавления файла через JavaScript или базу # файл с совпадающим именем должен лежать в папке Storage веб-сервера. Либо добавлять через GUI time.sleep(1) autoit.win_activate("Открытие") autoit.control_focus("Открытие", "Edit1") autoit.control_set_text( "Открытие", "Edit1", "G:\\Projects\\SeleniumOpenCart\\page_objects\\admin\\catalog\\test.jpg" ) time.sleep(1) autoit.control_click("Открытие", "Button1") time.sleep(1) with allure.step(f'accept and save download'): driver.switch_to.alert.accept() DownloadsPage(driver).save_btn_click() with allure.step(f'delete created download form database '): # Удаление созданной записи из базы db_items_new = len(connect("SELECT * FROM oc_download")) last_item_id = connect( "SELECT download_id FROM oc_download WHERE download_id=(SELECT max(download_id) FROM oc_download)" ) parsed_id = re.findall("\\d+", str(last_item_id)) row = ("DELETE FROM oc_download WHERE download_id=%s" % parsed_id[0]) delete_row(row) row_desc = "DELETE FROM oc_download_description WHERE download_id=%s" % parsed_id[ 0] delete_row(row_desc) assert db_items_default + 1 == db_items_new
def test_video_file_upload(self): drive = GoogleDrivePage(self.driver) drive.click_new_button() drive.file_upload() time.sleep(5) autoit.control_focus("Open", "") time.sleep(20) autoit.control_set_text("Open", "Edit1", "C:\\Users\\Dell\\Videos\\video1.mp4") time.sleep(10) autoit.control_click("Open", "Button1") time.sleep(5) print("Media file with extension .mp4 should be added to my drive.")
def up_load(self, path): """上传图片""" self.click_button('上传', *(self.mall_upload_loc)) # autoit处理 autoit.control_set_text( '打开', '[Class:Edit; instance:1]', path ) autoit.control_click( '打开', '[Class:Button; INSTANCE:1]' )
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 set_text(self, txt: str, control: str, *, timeout=15, focus=True): timer = Timer(timeout) while timer.not_expired: try: if focus: autoit.control_focus(self.title, control) autoit.control_set_text(self.title, control, txt) return 0 except Exception as e: # print(f"[Exception]--> {e}") pass if timer.expired: return -2
def LancamentoNroPrevenda(): log.EscreverLog('Tela de Informar Nro Prevenda') try: Variaveis.Tempo = (Variaveis.TempoAdd + 10) log.EscreverLog('Tempo. ate ' + str(Variaveis.Tempo) + ' segundos') autoit.win_wait_active("[Class:TFRM_NUMPREVENDA]", Variaveis.Tempo) log.EscreverLog('Tela de Nro Pre-venda') if Variaveis.DocFiscal == "PREV": if Variaveis.PrevAuto == 'S': log.EscreverLog('Numero de Pre-venda Automatico') log.EscreverLog('Confirma Pre-venda') autoit.control_click("[Class:TFRM_NUMPREVENDA]", "TVSMColorButton1") Tempo.Click() if Variaveis.PrevAuto == 'N': log.EscreverLog('Informar Numero de Pre-venda') Sai = 'N' while Sai == 'N': log.EscreverLog("Numero Prevenda: " + str(Variaveis.NroPrevenda)) Variaveis.NroPrevenda = Variaveis.NroPrevenda + 1 log.EscreverLog("Numero Prevenda: " + str(Variaveis.NroPrevenda)) autoit.control_set_text("[Class:TFRM_NUMPREVENDA]", "TRzNumericEdit1", str(Variaveis.NroPrevenda)) Tempo.Dig() log.EscreverLog("Confirmando Numero: " + str(Variaveis.NroPrevenda)) Tecla.Enter() try: Variaveis.Tempo = (Variaveis.TempoAdd + 1) log.EscreverLog('Tempo. ate ' + str(Variaveis.Tempo) + ' segundos') autoit.win_wait_active("[Class:TFRM_VSMTASKDIALOG]", Variaveis.Tempo) log.EscreverLog( str(Variaveis.NroPrevenda) + ' Numero Pre-venda ja existente') Tecla.Enter() log.EscreverLog("Add Numero Proxima Prevenda: ") except: log.EscreverLog('Confirma Pre-venda') autoit.control_click("[Class:TFRM_NUMPREVENDA]", "TVSMColorButton1") Tempo.Click() Sai = 'S' except: Tempo.TeclaAcao()
def send_attachment(): # Attachment Drop Down Menu clipButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/div/span') clipButton.click() time.sleep(1) # To send Videos and Images. mediaButton = browser.find_element_by_xpath( '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button' ) mediaButton.click() time.sleep(3) hour = datetime.datetime.now().hour # After 5am and before 11am scheduled this. if (hour >= 5 and hour <= 11): image_path = os.path.join(os.getcwd(), "Media", "goodmorning.jpg") # After 9pm and before 11pm schedule this elif (hour >= 21 and hour <= 23): image_path = os.path.join(os.getcwd(), "Media", "goodnight.jpg") else: # At any other time schedule this. image_path = os.path.join(os.getcwd(), "Media", "howareyou.jpg") if "autoit" in sys.modules: autoit.control_focus("Open", "Edit1") autoit.control_set_text("Open", "Edit1", (image_path)) autoit.control_click("Open", "Button1") elif "applescript" in sys.modules: applescript.tell.app("System Events", 'keystroke "G" using {command down, shift down}') applescript.tell.app("System Events", "delay 1") applescript.tell.app("System Events", 'keystroke "' + image_path + '"') applescript.tell.app("System Events", "delay 1") applescript.tell.app("System Events", "keystroke return") applescript.tell.app("System Events", "delay 1") applescript.tell.app("System Events", "keystroke return") applescript.tell.app("System Events", "delay 1") else: print("Sending attachments is not supported on your system") return time.sleep(3) whatsapp_send_button = browser.find_element_by_xpath( '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span' ) whatsapp_send_button.click()
def send_image(image_path): find_by_xpath_click('//*[@id="main"]/header/div[3]/div/div[2]/div') find_by_xpath_click('//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button') while True: try: autoit.control_focus("Open","Edit1") autoit.control_set_text("Open","Edit1",(image_path) ) autoit.control_click("Open","Button1") break except: sleep(random.randrange(1,3)) find_by_xpath_click('//*[@id="app"]/div/div/div[1]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span')
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 add_file(self, resource): # Open an add file window autoit.win_wait_active(WINDOW_MAIN) autoit.control_click(WINDOW_MAIN, BUTTON_ADD_FILE) # Open a file autoit.win_wait_active(WINDOW_OPEN) autoit.control_set_text(WINDOW_OPEN, FORM_FILE, resource.ts_file) autoit.control_click(WINDOW_OPEN, BUTTON_OPEN) # ............. # Choose a clip # ............. # Fill a clip name autoit.win_wait_active(WINDOW_EDIT) autoit.control_set_text(WINDOW_EDIT, FORM_CLIP_NAME, resource.name) autoit.control_click(WINDOW_EDIT, BUTTON_OK)
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