def setUp(self): Timings.Defaults() self.app = Application().start( os.path.join(mfc_samples_folder, u'CtrlTest.exe')) self.dlg = self.app.Control_Test_App
from pywinauto.application import Application app = Application(backend='uia').start("notepad.exe") dlg = app.window(best_match='Безымянный') dlg.print_control_identifiers(depth=3) menu = dlg.Menu2 item = menu.MenuItem item.print_control_identifiers() item['click'] menu.select() menu.MenuItem(best_match='Файл').click() # menu_select("File").click() #mi = dlg_spec.MenuItem('Файл') #edit1 = dlg_spec['Файл'].wrapper_object() #edit1.type_keys('test') # Опишем окно, которое хотим найти в процессе Notepad.exe # dlg_spec = app['Безымянный'] # ждем пока окно реально появится # actionable_dlg = dlg_spec.wait('visible') #dlg_spec.wrapper_object('Файл->Сохранить')
#!/usr/bin/env python # -*- coding: UTF-8 -*- # # auth: libinfei/[email protected] # time: 2018/12/02 # desc: 找到进程,将其kill #-------------------------------------------------------------------------------------------------- from pywinauto.application import Application app = Application(backend='uia').connect(title="任务管理器") app.Dialog.set_focus() dlg_main = app.Dialog.Pane.ListBox item = dlg_main.ListItem for item in dlg_main.items(): #print(item.item_data()) #item.select() try: if item.text() == "wpscenter.exe": print(item.Text()) except Exception: pass
#execute_word.py #imports from log import Log from datetime import datetime from pywinauto.application import Application Log.open() #Here starting the automation Log.print('>>>The execution STARTS HERE!\n\n') dateExecution = datetime.now().strftime('%Y%m%d_%H%M%S') app = Application(backend='uia') app.start('C:\Program Files\Microsoft Office\Office15\WINWORD.exe') word = app.Dialog #Creating a blank document word.child_window(title="Documento em branco", auto_id="AIOStartDocument", control_type="Hyperlink").type_keys('{ENTER}') #Typing and personalizing the document word.type_keys('Estou{SPACE}') word.child_window(title="Sublinhado", control_type="Button").click() word.child_window(title="Página 1", auto_id="UIA_AutomationId_Word_Page_1", control_type="Custom").type_keys('testando') word.child_window(title="Sublinhado", control_type="Button").click() word.child_window(title="Página 1", auto_id="UIA_AutomationId_Word_Page_1",
from __future__ import print_function from pywinauto.application import Application import time app = Application().start_("Notepad") dlg = app.Window_(title='Untitled - Notepad', class_name='Notepad') dlg.edit.SetEditText("Here is some text\r\n and some more") time.sleep(10) app.kill_()
def connect(self, client_path=None): self._app = Application().start(client_path) self._main = self._app.top_window()
from pywinauto.application import Application import time as hack fake = input("What is your name: ") fakel = input("Are you sure you want to run the script? ") print("I'm running anyways :p") print("Executing script... Script started") hack.sleep(1) print("Hacking You...") hack.sleep(2) app = Application().start("notepad.exe") app.UntitledNotepad.menu_select("View->Zoom->Zoom In") app.UntitledNotepad.Edit.type_keys("Hello " + fake + "! You Have been f****d!!!", with_spaces=True) app.UntitledNotepad.menu_select("Edit->Time/Date")
def test_start_problem(self): """Verify start_ raises on unknown command""" self.assertRaises(AppStartError, Application().start, 'Hiya')
def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() self.app = Application().start("Notepad") self.dlgspec = self.app.UntitledNotepad self.ctrlspec = self.app.UntitledNotepad.Edit
def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Slow() self.app = Application().start('explorer.exe "' + mfc_samples_folder_32 + '"') self.desktop = Desktop(backend='uia')
def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() self.app = Application(backend='win32').start( os.path.join(mfc_samples_folder, u"CmnCtrl3.exe")) self.desktop = Desktop()
def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Slow() self.app = Application(backend='uia').start( os.path.join(mfc_samples_folder, u"RowList.exe")) self.dlg = self.app.RowListSampleApplication
# -*- coding: utf-8 -*- import sys import pywinauto from pywinauto.application import Application app_name = input('Please input app name > ') app = Application(backend='uia').connect(path=app_name) try: list1 = app.Dialog.List1 if list1.item_count() >= 3: list1.item(2).select().double_click_input() print(app.Dialog.ListView1.wrapper_object()) print(list1.wrapper_object()) except pywinauto.MatchError as e: sys.exit(e) # References: # [Is there a way to speed up pywinauto?](https://stackoverflow.com/questions/59358742/is-there-a-way-to-speed-up-pywinauto) # [Any possibility to make backend uia faster](https://github.com/pywinauto/pywinauto/issues/256) # [pywinauto and listitem selection](https://stackoverflow.com/questions/41112765/pywinauto-and-listitem-selection)
from pywinauto.application import Application app = Application().Start( cmd_line=u'"B:\\Program Files (x86)\\AbilityCash\\AbilityCash.exe" ') menu_item = app[u'AC-MW'].MenuItem(u'Просмотр->Операции Alt+2').Click() menu_item2 = app[u'AC-MW'].MenuItem(u'Действия->Добавить Insert').Click() window = app.Dialog # <--- Переход к работе с диалогом window[u'AC-BC'].Click() # <--- Приход window[u'AC-BC7'].Click() # <--- Не выполнена # window[u'AC-BC5'].Click() # <--- выполнена # window[u'AC-BC2'].Click() # <--- Расход window[u'AC-E'].type_keys('10.00') # <--- Установить значение в ячейку window[u'AC-E2'].type_keys( 'ВСТАВИЛ ЗНАЧЕНИЕ!') # <--- Установить значение в ячейку window[u'AC-BC11'].Click() # <--- Кнопка Добавить app.Kill_()
def slotConfigTool(self): global num # 打开程序 app = Application(backend="uia").start( r'C:/Users/Admin/Desktop/测试/项目需求/2019-7-11之后/测试小程序/SlotConfigTool/SlotConfigTool(24).exe' ) # 查到这个放水表测试程序主页面的控件树 dlg_spec = app['SlotConfigTool'] dlg_spec.print_control_identifiers() # 点击第一个Click app['SlotConfigTool'].Clicknum.click() # 点击第二个Click # app['SlotConfigTool'].Click2.click() # 查到第一个Click页面的控件树 dlg_spec1 = app['修改配置Dialog'] dlg_spec1.print_control_identifiers() # 定位香蕉输入框-通过控件的text或者title来查找控件- # edit = dlg_spec['香蕉'] # 1 xiangjiao = dlg_spec['Edit1'] # 2 # edit = dlg_spec.Edit0 # 3 # 操作输入框-第一种方法是直接设置edit的text,而第二种是在里面模拟键盘输入 xiangjiao.set_text(r'333') # 1 # edit.type_keys(r'E:\test test .exe',with_spaces = True) # 2 # 西瓜 xigua = dlg_spec['Edit2'] xigua.set_text(r'200') # 柠檬 ningmeng = dlg_spec['Edit3'] ningmeng.set_text(r'67') # 葡萄 putao = dlg_spec['Edit4'] putao.set_text(r'67') # 猕猴桃 mihoutao = dlg_spec['Edit5'] mihoutao.set_text(r'67') # 樱桃 yingtao = dlg_spec['Edit6'] yingtao.set_text(r'67') # 铃铛 lingdang = dlg_spec['Edit7'] lingdang.set_text(r'67') # BAR BAR = dlg_spec['Edit8'] BAR.set_text(r'66') # bouns bouns = dlg_spec['Edit9'] bouns.set_text(r'66') # 大7 da_7 = dlg_spec['Edit10'] da_7.set_text(r'0') # Wild wild = dlg_spec['Edit11'] wild.set_text(r'0') # Wild3 wild3 = dlg_spec['Edit12'] wild3.set_text(r'0') # 第一个Cilck的 Free Spin child_window(title="Free Spin:", auto_id="1013", control_type="Edit").set_text(r'111') Spin1 = dlg_spec['Edit13'] Spin1.set_text(r'333') Spin2 = dlg_spec['Edit14'] Spin2.set_text(r'200') Spin3 = dlg_spec['Edit15'] Spin3.set_text(r'67') Spin4 = dlg_spec['Edit16'] Spin4.set_text(r'67') Spin5 = dlg_spec['Edit17'] Spin5.set_text(r'67') Spin6 = dlg_spec['Edit18'] Spin6.set_text(r'67') Spin7 = dlg_spec['Edit19'] Spin7.set_text(r'67') Spin8 = dlg_spec['Edit20'] Spin8.set_text(r'66') Spin9 = dlg_spec['Edit21'] Spin9.set_text(r'66') Spin10 = dlg_spec['Edit22'] Spin10.set_text(r'0') Spin11 = dlg_spec['Edit23'] Spin11.set_text(r'0') Spin12 = dlg_spec['Edit24'] Spin12.set_text(r'0') # 保存配置 app['SlotConfigTool'].Button1.click() for i in range(13): # 打开程序 app = Application(backend="uia").start( r'C:/Users/Admin/Desktop/测试/项目需求/2019-7-11之后/测试小程序/SlotConfigTool/SlotConfigTool(24).exe' ) # 查到这个放水表测试程序主页面的控件树 dlg_spec = app['SlotConfigTool'] dlg_spec.print_control_identifiers() # 点击第num个Click app['SlotConfigTool'].Clicknum.click() # 点击第二个Click # app['SlotConfigTool'].Click2.click() # 查到第一个Click页面的控件树 dlg_spec1 = app['修改配置Dialog'] dlg_spec1.print_control_identifiers() # 定位香蕉输入框-通过控件的text或者title来查找控件- # edit = dlg_spec['香蕉'] # 1 xiangjiao = dlg_spec['Edit1'] # 2 # edit = dlg_spec.Edit0 # 3 # 操作输入框-第一种方法是直接设置edit的text,而第二种是在里面模拟键盘输入 xiangjiao.set_text(r'333') # 1 # edit.type_keys(r'E:\test test .exe',with_spaces = True) # 2 # 西瓜 xigua = dlg_spec['Edit2'] xigua.set_text(r'200') # 柠檬 ningmeng = dlg_spec['Edit3'] ningmeng.set_text(r'67') # 葡萄 putao = dlg_spec['Edit4'] putao.set_text(r'67') # 猕猴桃 mihoutao = dlg_spec['Edit5'] mihoutao.set_text(r'67') # 樱桃 yingtao = dlg_spec['Edit6'] yingtao.set_text(r'67') # 铃铛 lingdang = dlg_spec['Edit7'] lingdang.set_text(r'67') # BAR BAR = dlg_spec['Edit8'] BAR.set_text(r'66') # bouns bouns = dlg_spec['Edit9'] bouns.set_text(r'66') # 大7 da_7 = dlg_spec['Edit10'] da_7.set_text(r'0') # Wild wild = dlg_spec['Edit11'] wild.set_text(r'0') # Wild3 wild3 = dlg_spec['Edit12'] wild3.set_text(r'0') # 第一个Cilck的 Free Spin child_window(title="Free Spin:", auto_id="1013", control_type="Edit").set_text(r'111') Spin1 = dlg_spec['Edit13'] Spin1.set_text(r'333') Spin2 = dlg_spec['Edit14'] Spin2.set_text(r'200') Spin3 = dlg_spec['Edit15'] Spin3.set_text(r'67') Spin4 = dlg_spec['Edit16'] Spin4.set_text(r'67') Spin5 = dlg_spec['Edit17'] Spin5.set_text(r'67') Spin6 = dlg_spec['Edit18'] Spin6.set_text(r'67') Spin7 = dlg_spec['Edit19'] Spin7.set_text(r'67') Spin8 = dlg_spec['Edit20'] Spin8.set_text(r'66') Spin9 = dlg_spec['Edit21'] Spin9.set_text(r'66') Spin10 = dlg_spec['Edit22'] Spin10.set_text(r'0') Spin11 = dlg_spec['Edit23'] Spin11.set_text(r'0') Spin12 = dlg_spec['Edit24'] Spin12.set_text(r'0') # 保存配置 app['SlotConfigTool'].Button1.click() # 关闭按钮("X") # app['SlotConfigTool'].Button2.click() num = num + 1
if len(directories_to_process[0]) > 0: file_path_variable = str() for file_path_variable in directories_to_process: if len(file_path_variable) > 0: logger.info('Working with ' + file_path_variable) # logger.info('Working with ' + file_path_variable) # file_path_variable = filedialog.askdirectory(initialdir=curr_dir, # title='Please select a directory containing the data') # print("\nfile_path_variable = ", file_path_variable) from pywinauto.application import Application app = Application(backend="uia").start( 'C:/Users/rjaques/Software/NRCD/Current Version/NRCD.exe') app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='SCANNER').click() time.sleep(5) main_screen = app.window( best_match='National Roads Condition Database - V*') # app.window(best_match='', top_level_only=True) \ # .print_control_identifiers() app.window(best_match='', top_level_only=True) \ .child_window(best_match='Enter System').click()
def change_vpn_ip(): # # wifi_netflix = 'Livebox-3DB6' # # change_wifi(wifi_netflix) # # sleep(3) # # input('wifi chagned') # # proxy = 'p.appcloud.digital:9999' # # options.add_argument('--proxy-server=socks5://' + proxy) sleep(2) sleep(2) try: os.environ.update({"__COMPAT_LAYER": "RUnAsInvoker"}) app = Application().start('C:\\3.26\\Client.exe') sleep(2) w = app.top_window() w.set_focus() sleep(2) sleep(1) w.set_focus() sleep(0.5) user_id = 'olorus' password = '******' w.set_focus() sleep(0.3) for i in range(15): sleep(0.1) keyboard.send_keys('{DELETE}') sleep(2) w.set_focus() sleep(0.3) keyboard.send_keys(user_id) sleep(1) w.set_focus() sleep(0.3) keyboard.send_keys('{TAB 1}') sleep(1) for i in range(15): sleep(0.1) keyboard.send_keys('{DELETE}') sleep(1) w.set_focus() sleep(0.3) keyboard.send_keys(password) sleep(1) w.set_focus() sleep(0.2) keyboard.send_keys('{TAB 1}') keyboard.send_keys('{TAB 1}') sleep(1) w.set_focus() sleep(0.2) keyboard.send_keys('{ENTER 2}') sleep(1) sleep(2) sleep(1) try: app_b = Application().connect(path='annoucement.exe') w_b = app_b.top_window() w_b.close() sleep(1) except: pass sleep(2) sleep(1) except: pass sleep(2) # os.popen('"C:/Users/olorus/Downloads/3.26/ProxyTool/AutoProxyTool.exe" -changeproxy/PT') sleep(3) sleep(2) app1 = Application().connect(path='Client.exe') w1 = app1.top_window() w1.set_focus() sleep(2) w1.set_focus() os.popen('"C:/3.26/ProxyTool/AutoProxyTool.exe" -changeproxy/CH') print('done proxy ip change') sleep(3) # os.popen('"C:/3.26/ProxyTool/AutoProxyTool.exe" -changeproxy/PT') # sleep(3) sleep(2) sleep(1) # change_vpn_ip()
def assign_la(app, file_path_variable): logger.info('starting local authority assignment') app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Attributes').click() time.sleep(15) group_control = app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Local Authority Attribute", auto_id="3", control_type="Group") group_control.child_window(title="Select Batch File", auto_id="7", control_type="Button") \ .click() # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(title="Local Authority Attribute", auto_id="3", control_type="Group") \ # .child_window(title="Select Batch File", auto_id="7", control_type="Button") \ # .click() filename = file_path_variable + '/BatchList.txt' print("\nfilename is ", filename) logger.info('File name is ' + filename) filename = filename.replace('/', '\\') time.sleep(15) app4 = Application(backend="uia").connect(title_re='Select a batch file', visible_only=True) print("\nConnect app4 filename is ", filename) logger.info('Connecting to the batch file selection with ' + filename) time.sleep(60) # app4.window(title_re='Select a batch file').File_name_Edit.set_text(filename) # app4.window(title_re='Select a batch file').type_keys(filename, with_spaces=True) # app4.window(title_re='Select a batch file').print_control_identifiers() app4.window( title_re='Select a batch file').File_name_Edit.set_text(filename) # app4.window(title_re='Select a batch file').print_control_identifiers() # app4.window(title_re='Select a batch file').type_keys('%o') batch_splitbutton1 = app4.window(title_re='Select a batch file') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_splitbutton1).click() del app4 # use the location of the BatchList.txt to extract the local authority. It's two from the end. local_authority = filename.split("\\")[-2] # print(local_authority) logger.info('starting to assign attributes for ' + local_authority) # Load the human name to database name csv table lookup_table = '//trllimited/data/INF_ScannerQA/Audit_Reports/Tools/LA_to_NRCD_Name.csv' la_lookup_table = pd.read_csv(lookup_table, index_col='Audit_Report_name', dtype={'INDEX': str}) la_db_name: str = la_lookup_table.loc[local_authority, "NRCD_Name"] # survey_year = "2019/20" # print(la_db_name) logger.info('DB name for the LA is ' + la_db_name) # app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group").print_control_identifiers() time.sleep(15) # app.window(best_match='National Roads Condition Database - Version *') \ # .child_window(title="Local Authority Attribute", control_type="Group") \ # .child_window(best_match='3',control_type="ComboBox").type_keys("%{DOWN}") # app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(auto_id='6', control_type="ComboBox").select(la_db_name) # print(la_db_name) batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Local Authority Attribute', control_type="Group") \ .child_window(auto_id='6', control_type="ComboBox").wait('exists enabled visible ready') from pywinauto.controls.win32_controls import ComboBoxWrapper ComboBoxWrapper(batch_combobox1).select(la_db_name) batch_combobox2 = app.window(best_match='National Roads Condition Database - Version*') \ .child_window(best_match='Local Authority Attribute', control_type="Group") \ .child_window(auto_id='4', control_type="ComboBox") # .wait('exists enabled visible ready') ComboBoxWrapper(batch_combobox2).select(" 2019/20") time.sleep(15) # print(survey_year) app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title="Assign Local Authority", auto_id="5", control_type="Button") \ .click() logger.info('waiting for LA assignment to complete') time.sleep(60) # the following contains 10000 seconds. This is to stop the wait timing out, it retries each 90 secs # but the attributes should be finished in under 6 hours... or even one hour. app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title='NRCD', control_type="Window") \ .child_window(title="OK", auto_id="2", control_type="Button") \ .wait("exists ready", timeout=10000, retry_interval=90) app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title='NRCD', control_type="Window") \ .child_window(title="OK", auto_id="2", control_type="Button").click() app.window(best_match='National Roads Condition Database - Version*') \ .child_window(title="Exit", auto_id="11", control_type="Button").click() return
ymin = drop_height * y ymax = drop_height * (y + 1) for x in range(board_width): xmin = drop_width * x xmax = drop_width * (x + 1) box = (xmin, ymin, xmax, ymax) img = board_img.crop(box) img = img.resize((DROP_SIZE, DROP_SIZE)) img.save("sample/drop_{}s.png".format(y * board_width + x + 1)) color = k_nn(img) board.append(color) return board #Apowersoftとの接続を試みる(失敗なら起動) app = Application() try: app.connect(path=APP_DIR) except: app.start(cmd_line=APP_DIR) #app[APP_NAME].move_window(x=None, y=None, width=APP_WIDTH, height=APP_HEIGHT, repaint=True) # 事前にテンプレート画像を1次元ベクトル化しておく for i in range(1, TEMPLATE_NUM + 1): img = Image.open("template/drop_{}.png".format(i)) img = img.resize((DROP_SIZE, DROP_SIZE)) templates.append(np.asarray(img, dtype="int32")) api = Flask(__name__) CORS(api)
def data_loading(app, file_path_variable): # from pywinauto.controls.win32_controls import ComboBoxWrapper # click on the loading button app.window(best_match='National Roads Condition Database - Version*', top_level_only=True).child_window(best_match='Loading').click() # if the file_path_variable directory contains a file 'BatchList' use the 'Select Batch File' # else use 'Create Batch file' if os.path.isfile(file_path_variable + '/BatchList.txt'): filename = file_path_variable + '/BatchList.txt' print("\nfile name exists using Select", filename) time.sleep(30) app.window(best_match='National Roads Condition Database - Version', top_level_only=True) \ .child_window(best_match='Select Batch file').click() filename = filename.replace('/', '\\') print("\nfile exists", filename) time.sleep(15) app2 = Application(backend="uia").connect( title_re='Select a batch file', visible_only=True) print("\nConnect app2 filename is ", filename) # edit_text_box1 = app2.window(title_re='Select a batch file') \ # .child_window(best_match="File name:") # from pywinauto.controls.win32_controls import EditWrapper # EditWrapper(edit_text_box1).set_text(filename) # app2.window(title_re='Select a batch file').type_keys(filename, with_spaces=True) app2.window( title_re='Select a batch file').File_name_Edit.set_text(filename) # app2.window(title_re='Select a batch file').print_control_identifiers() # app2.window(title_re='Select a batch file').type_keys('%o') batch_split_button2 = app2.window(title_re='Select a batch file') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button2).click() # app2.window(title_re='Select a batch file').OpenSplitButton.click_input # app2.window(title_re='Select a batch file') \ # .child_window(title='Pane1') \ # .child_window(title='Open', auto_id=1).click() # .child_window(title='Open', auto_id=1, control_type="UIA_SplitButtonControlTypeId").click() # .child_window(title='SplitButton6').click() del app2 else: # else pick the first .hmd file and use 'Create Batch File' print("\nBatchfile file missing") # app.window(best_match='National Roads Condition Database - Version', top_level_only=True).child_window( # best_match='OK').click() #filename = filename.replace('/', '\\') file_search_variable = (file_path_variable + '/*.hmd').replace( '/', '\\') print("\nfile_search_variable = ", file_search_variable) filename = glob.glob(file_search_variable) filename = filename[1] print("\nFile found : ", filename[1]) time.sleep(20) # click on 'Create Batch File' then OK on the following window app.window(best_match='National Roads Condition Database - Version *', top_level_only=True) \ .child_window(best_match='Create Batch file').click() time.sleep(30) app.window(best_match='National Roads Condition Database - Version *') \ .child_window(best_match='NRCD') \ .child_window(best_match='OK').click() # app.window(best_match='National Roads Condition Database Version *') \ # .child_window(best_match='OK').click() time.sleep(30) # There will be a file selection window. Connect to it (it's not part of NRCD) # So it's a new application. app3 = Application(backend="uia").connect( title='Create a file in the required directory') print("\nconnect app3") time.sleep(15) # edit_text_box2 = app3.window(title_re='Select a batch file') \ # .child_window(best_match="File name:") # from pywinauto.controls.win32_controls import EditWrapper # EditWrapper(edit_text_box2).set_text(filename) # put the filename that was found into the filename box app3.window(title_re='Create a file in the required directory') \ .File_name_Edit.set_text(filename) # app3.window(title_re='Create a file in the required directory').type_keys(filename[0], with_spaces=True) # app3.window(title_re='Create a file in the required directory').print_control_identifiers() # app3.window(title_re='Create a file in the required directory') \ # .Open3_SplitButton.click() # Click on the open button, this is a bit more involved so that it works with a locked screen. batch_split_button1 = app3.window(title_re='Create a file in the required directory') \ .child_window(auto_id='1', control_type="SplitButton") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button1).click() # child_window(title="Open", auto_id="1", control_type="SplitButton") # .child_window(best_match='Open3').click() del app3 # if the file_path_variable directory string contains WDM if "WDM" in file_path_variable: # then Survey Contractor = WDM survey_contractor: str = "WDM" # else if the directory string contains 'G-L' select survey contractor 'Ginger-Lehmann' elif "G-L" in file_path_variable: survey_contractor: str = "Ginger-Lehmann" # it's not one of the two we know about. Should another contractor start surveying then add another 'elif' else: survey_contractor = "Unknown" print(survey_contractor) # ComboBoxWrapper(group_control.child_window(auto_id="24", # control_type="ComboBox")).select(la_db_name) # app.window(best_match='National Roads Condition Database', # top_level_only=True).print_control_identifiers() # batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(title="OK", auto_id="6", control_type="Button")\ # .wait('exists enabled visible ready') # from pywinauto.controls.uia_controls import ComboBoxWrapper # from pywinauto.controls.win32_controls import EditWrapper # batch_combobox1 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(title="Survey Contractor", auto_id="1", control_type="Group") \ # .child_window(title="OK", auto_id="6", control_type="Button") # best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor' # app.window(best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor').Edit.type_keys(surveycontractor) from pywinauto.controls.win32_controls import ComboBoxWrapper surveyor_combobox = app.window(best_match='National Roads Condition Database') \ .child_window(best_match='Survey Contractor', control_type='Group') \ .child_window(auto_id="3", control_type="ComboBox") # .child_window(title="Survey Contractor", auto_id="5", control_type="Edit") # EditWrapper(surveyor_menu).set_text(survey_contractor) ComboBoxWrapper(surveyor_combobox).select(survey_contractor) # contractor_combobox = app.window(best_match='National Roads Condition Database', # top_level_only=True).child_window(best_match='Survey Contractor') # ComboBoxWrapper(contractor_combobox).select(survey_contractor) # contractor_combobox.Survey_Contractor_Edit.set_text(survey_contractor) # batch_combobox2 = app.window(best_match='National Roads Condition Database - Version*') \ # .child_window(best_match='Local Authority Attribute', control_type="Group") \ # .child_window(auto_id='4', control_type="ComboBox") # .wait('exists enabled visible ready') # click 'OK' to close the data loading window as we have all the appropriate details entered in the window. app.window(best_match='National Roads Condition Database') \ .child_window(best_match='OK').click() # back on the NRCD main screen, click the process radio button then the actual 'Process' button app.window(best_match='National Roads Condition Database - Version *', top_level_only=True).child_window(best_match='Process').click() # print(filename) # The log entry contains the first file to be loaded (the rest will not appear and NRCD uses the # batchfile to find them logger.info('Starting loading with ' + filename[0]) time.sleep(60) # wait for the loading to finish. It checks the number of windows open for NECD.exe. If these are less than # two the section is complete, otherwise it loops. while nrcd_running_check("2"): logger.info('waiting for loading to complete') time.sleep(300) logger.info('loading completed') return # back to main
from pywinauto.application import Application import pyautogui import time app = Application().start("C:\\Program Files\\blp\\Wintrv\\WINTRV.EXE") time.sleep(40) #Bring desktop back pyautogui.click(1910, 1060) time.sleep(5) #Open first screen only pyautogui.click(330, 1060) time.sleep(1) pyautogui.click(280, 960) time.sleep(1) pyautogui.click(500, 500) time.sleep(15) pyautogui.click(100, 270) pyautogui.typewrite('jaycsa') time.sleep(3) pyautogui.click(100, 370) pyautogui.typewrite('password') time.sleep(3) pyautogui.click(100, 460) time.sleep(45) #For launchpad pyautogui.click(1880, 5) #For mini launchpad time.sleep(5) pyautogui.click(325, 5)
def scanner_qa(app, file_path_variable): from pywinauto.controls.win32_controls import ComboBoxWrapper from pywinauto.controls.win32_controls import ButtonWrapper import re # there is a regex search below ! main_screen = app.window( best_match='National Roads Condition Database - V*') # turn all the process check boxes off. main_screen_process_checkbox = main_screen.child_window( title="Process", auto_id="15", control_type="CheckBox") main_screen_process_checkbox2 = main_screen.child_window( title="Process", auto_id="16", control_type="CheckBox") main_screen_process_checkbox3 = main_screen.child_window( title="Process", auto_id="17", control_type="CheckBox") main_screen_process_checkbox4 = main_screen.child_window( title="Process", auto_id="18", control_type="CheckBox") ButtonWrapper(main_screen_process_checkbox).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox2).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox3).uncheck_by_click() ButtonWrapper(main_screen_process_checkbox4).uncheck_by_click() filename = file_path_variable.replace('/', '\\') print(filename) # time.sleep(15) # use the location of the file_path_variable to extract the local authority, nation and year. local_authority = filename.split("\\")[-1] nation = filename.split("\\")[-2] year: str = re.search('[1-2][0-9]{3}', filename).group(0) # regex search # logger.info('starting Scanner QA output for ' + local_authority) # print(local_authority) print(nation) print(year) logger.info('starting SCANNER QA for ' + local_authority) # Load the human name to database name csv table lookup_table_filename = '//trllimited/data/INF_ScannerQA/Audit_Reports/Tools/LA_to_NRCD_Name.csv' la_lookup_table = pd.read_csv(lookup_table_filename, index_col='Audit_Report_name', dtype={'INDEX': str}) la_db_name: str = la_lookup_table.loc[local_authority, "NRCD_Name"] # enter the Scanner QA section of NRCD and wait for the Survey QA options group to exist. app.window( best_match='National Roads Condition Database', top_level_only=True).child_window(best_match='Scanner QA').click() time.sleep(10) app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Survey QA Options", auto_id="9", control_type="Group") \ .wait("exists ready", timeout=90, retry_interval=60) group_control = app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="Survey QA Options", auto_id="9", control_type="Group") # groupcontrol.print_control_identifiers() # exclude the previous year and the U roads (uncheck_by_click) then select the LA abd survey year. ButtonWrapper( group_control.child_window( title="Include Previous Year", control_type="CheckBox")).uncheck_by_click() ButtonWrapper( group_control.child_window( title="U Roads", control_type="CheckBox")).uncheck_by_click() ComboBoxWrapper( group_control.child_window(auto_id="24", control_type="ComboBox")).select(la_db_name) ComboBoxWrapper( group_control.child_window(auto_id="25", control_type="ComboBox")).select(" 2019/20") # Export the data group_control.child_window(auto_id="26", title="Export QA Data").click() # print("Waiting for a user !") # build output file name. # output_file_name = os.path.normpath("//trllimited/data/INF_ScannerQA/Audit_Reports/NRCD Data" output_file_name = os.path.normpath("C:/Users/rjaques/temp/Data/" + local_authority + "_" + year + ".csv") # add the year combination (year and '-' and 2 digit next year so # convert year string to numeric, add one, convert back to string and use the last 2 chars print(year) print(int(year)) print(int(year) + 1) print(str(int(year) + 1)) next_year = str(int(year) + 1)[-2:] print(next_year) survey_period = year + '-' + next_year print(survey_period) print(output_file_name) time.sleep(60) # connect to the output file name selection window and enter the name from above and save the file. app5 = Application(backend="uia").connect( title_re='Select an output file name', visible_only=True) print("\nConnect app5 filename is ", output_file_name) time.sleep(30) # app5.window(title_re='Select an output file name').print_control_identifiers() app5.window(title_re='Select an output file name').File_name_Edit.set_text( output_file_name) # app5.window(title_re='Select an output file name').print_control_identifiers() # app4.window(title_re='Select a batch file').type_keys('%o') batch_split_button1 = app5.window(title_re='Select an output file name') \ .child_window(title='Save', auto_id='1', control_type="Button") from pywinauto.controls.win32_controls import ButtonWrapper ButtonWrapper(batch_split_button1).click() # app5.window(title_re='Select an output file name').type_keys(output_file_name, with_spaces=True) # app5.window(title_re='Select an output file name').Save.click() del app5 time.sleep(60) logger.info('waiting for ' + local_authority + ' QA output to finish') app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="NRCD") \ .wait("exists ready", timeout=10000, retry_interval=60) app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="NRCD") \ .print_control_identifiers() app.window(best_match='National Roads Condition Database - Version *') \ .child_window(title="NRCD").OK.click() # Wait patiently # while nrcd_running_check("2"): # logger.info('waiting for ' + local_authority + 'QA output to finish') # time.sleep(90) logger.info(local_authority + ' QA output complete') return # back to main code block
def test_send_a_message_from_one_ad(self): url_ad = "https://www.pap.fr/annonces/bureaux-paris-16e-r427800161" app = Application(backend="uia") # Ouvrir l'application Google Chrome app.start( "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe") time.sleep(7) # Open the Pap Application pywinauto.keyboard.send_keys(url_ad) time.sleep(5) # Press the 'Enter' button pywinauto.keyboard.send_keys('{ENTER}') time.sleep(10) # Clik on the form pywinauto.mouse.click(button='left', coords=(1150, 230)) time.sleep(3) # Go to the "Votre prénom" input pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.keyboard.send_keys("") # Go to the "Votre nom" input time.sleep(3) pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.keyboard.send_keys("") # Go to the "Votre email" input time.sleep(3) pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.keyboard.send_keys("") # Go to the "Votre téléphone" input time.sleep(3) pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.keyboard.send_keys("") # Go to the "Votre message" input time.sleep(3) pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.keyboard.send_keys(""" """) # Uncheck the "Je souhaite recevoir les annonces correspondant à ma recherche" checkbox time.sleep(3) pywinauto.keyboard.send_keys("{VK_TAB}") time.sleep(3) pywinauto.mouse.click(button='left', coords=(1000, 330)) # Click on the "Envoyer votre message" button time.sleep(3) pywinauto.mouse.click(button='left', coords=(1000, 400)) # Close the brower time.sleep(7) pywinauto.keyboard.send_keys('%{F4}')
from twitchio.ext import commands from tinydb import TinyDB, Query from tinydb.operations import add, subtract import json from pywinauto.application import Application from pywinauto.keyboard import send_keys from pydub import AudioSegment from pydub.playback import play #init cfg file with open('config.json') as json_config: config = json.load(json_config) #init application for pywinauto app = Application().connect( path='F:\SteamLibrary\steamapps\common\GRIS\GRIS.exe') app_dialog = app.top_window() app_dialog.maximize() app_dialog.set_focus() state = [] #init db db = TinyDB('twitch.json') Users = db.table('Users') #dbfunctions def User_operator(uname): Querydata = Users.get(Query().name == uname) if Querydata == None: Users.insert({
def Daochu_toucunbaobiao(exePath, imPath, exPath, fundName, gzPath, gzName, gzPW, cwPath, cwName, cwPW, o32Path, o32Name, o32PW, year, month, day, blacklist, email_server_url, email_server_port, sender_email, sender_passwd, reciever_email, jijinListTotal, jijinListSelected): from pywinauto.application import Application from pywinauto.keyboard import send_keys from pywinauto import mouse from pywinauto import timings from time import sleep from common import restart_if_app_exist, verify_control_exception, send_email_to_admin from login import process_app_login # exepath = r"C:\Program Files (x86)\赢时胜资产财务估值系统V2.5\YssReport.exe" restart_if_app_exist(cwPath) sleep(3) app = Application(backend="win32").start(cwPath) #处理登录 process_app_login(app, cwName, cwPW) sleep(1) #--------------------------------------------------------------------------------------------------- #打开报表左侧“现金头寸汇总表” dlg_main = app["ThunderRT6MDIForm"] dlg_main.set_focus() mouse.click(coords=(182, 227)) #TODO sleep(1) mouse.click(coords=(86, 309)) #TODO #dlg_main["ThunderRT6PictureBoxDC7"].set_focus() #dlg_main["ThunderRT6PictureBoxDC7"].click() sleep(1) #输入日期 dlg_main["DTPicker20WndClass2"].set_focus() SendKeys(year) SendKeys("{RIGHT}") SendKeys(month) SendKeys("{RIGHT}") SendKeys(day) SendKeys("{ENTER}") sleep(2) #just for test 为了快速调试减少基金数 #dlg_main["功能选项>>"].set_focus() #dlg_main["功能选项>>"].click() #sleep(2) #app["ThunderRT6Frame"]["全选"].set_focus() #app["ThunderRT6Frame"]["全选"].uncheck() #mouse.click(coords=(687,446)) #点击浏 览 dlg_main["浏 览"].set_focus() dlg_main["浏 览"].click() sleep(2) while True: #等待保存成功后的弹窗 try: if verify_control_exception(app.top_window(), blacklist): send_email_to_admin("helloworld", email_server_url, email_server_port, sender_email, sender_passwd, reciever_email, exPath + "/对帐结果管理.xls") sleep(300) try: if not dlg_main["Progress Bar"].exists(): break dlg_main["Progress Bar"].wrapper_object() except Exception: break app.top_window()["确定"].set_focus() app.top_window()["确定"].click() sleep(1) except Exception: None #点击保存excel dlg_main["msvb_lib_toolbar"].click(coords=(71, 10)) #输出excel dlg_outxls = app["输出EXCEL"] dlg_outxls.set_focus() dlg_outxls.Edit2.set_text(exPath) dlg_outxls.Edit3.set_text(r"对帐结果管理.xls") dlg_outxls["确 定"].click() sleep(2) #等待保存的进度条出现 while True: #等待保存成功后的弹窗 try: if verify_control_exception(app.top_window(), []): send_email_to_admin("helloworld", email_server_url, email_server_port, sender_email, sender_passwd, reciever_email, exPath + "/对帐结果管理.xls") sleep(300) try: app["导出EXCEL文件Dialog"]["是(Y)"].set_focus() app["导出EXCEL文件Dialog"]["是(Y)"].click() except Exception: None try: if dlg_outxls["ProgressBar20WndClass"].exists(): break except Exception: None except Exception: None #等待进度条完成 while True: #等待保存成功后的弹窗 try: try: app["导出EXCEL文件Dialog"]["确定"].set_focus() app["导出EXCEL文件Dialog"]["确定"].click() sleep(1) except Exception: None try: if not dlg_outxls["ProgressBar20WndClass"].exists(): break except Exception: break except Exception: None #退出 try: dlg_main.close() except timings.TimeoutError: app.top_window()["是(Y)"].click()
#!/usr/bin/env python # -*- coding: UTF-8 -*- # # auth: libinfei/[email protected] # time: 2018/12/02 # desc: 找到qq,然后找到联系人发送信息 # TODO(qq是dui的目前无法找到好的办法遍历里面的控件,暂时搁置) #-------------------------------------------------------------------------------------------------- from pywinauto.application import Application app = Application().connect( path=r"C:\Program Files (x86)\Tencent\QQ\Bin\qq.exe").TXGuiFoundation app.set_focus() app['莫恒等5个会话'].print_control_identifiers()
def openpaint(low, high): app = Application(backend="uia").start("mspaint.exe") cap = cv2.VideoCapture(0) time.sleep(2) pywinauto.mouse.move(coords=(200, 200)) time.sleep(2) c = 0 pywinauto.mouse.press(button='left', coords=(200, 200)) X = 200 Y = 200 c = 0 # This drives the program into an infinite loop. while (1): # Captures the live stream frame-by-frame _, frame = cap.read() frame = cv2.flip(frame, 3) c = c + 1 if (c == 100): break #c = c+1 #if(c==500): # break #frame = cv2.resize(frame,(1366,768)) # Converts images from BGR to HSV hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_red = np.array([75, 215, 130]) upper_red = np.array([95, 235, 210]) # Here we are defining range of bluecolor in HSV # This creates a mask of blue coloured # objects found in the frame. mask = cv2.inRange(hsv, low, high) # The bitwise and of the frame and mask is done so # that only the blue coloured objects are highlighted # and stored in res res = cv2.bitwise_and(frame, frame, mask=mask) #cv2.imshow('mask',mask) #cv2.imshow('res',res) im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) try: largest_area = sorted(contours, key=cv2.contourArea)[-1] x, y, w, h = cv2.boundingRect(largest_area) #cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2) pywinauto.mouse.press(button='left', coords=(X, Y)) pywinauto.mouse.move(coords=(x, y)) X, Y = x, y #cv2.imshow('frame',frame) # This displays the frame, mask # and res which we created in 3 separate windows. except: pass k = cv2.waitKey(5) if k == 27: break # Destroys all of the HighGUI windows. cv2.destroyAllWindows() # release the captured frame cap.release()
def __init__(self): self.app = Application() self.c = [] self.v = []
from pywinauto.application import Application from ctypes import * import os import sys import win32api, win32con, win32gui, time import pywinauto from abb import * app = Application().connect(process=GetProcess(TestAppName).ProcessID) app print 'end'
from pywinauto.application import Application from time import sleep from pywinauto.controls.win32_controls import ButtonWrapper app = Application(backend="uia").start( 'C:\Program Files\BMC Software\ARSystem\dataimporttool\launcher.exe') login = app.window(title_re="BMC Remedy Data Import - Login") login.edit2.set_text("super") login.button3.click() imp = app.window(title_re="BMC Remedy Data Import") imp["Open an existing mapping file."].click() imp["File name:Edit"].set_text("test")