def login(name=name, pw=pw, cert=cert): ''' # 파일에서 비번들 로드할경우 with open('./ignores/pw.txt') as f: itms = list(f.readlines()) pw = itms[0].strip() cert = itms[1].strip() ''' # 어플리케이션 실행 app = pywinauto.Application() app.start('C:\\CREON\\STARTER\\coStarter.exe /prj:cp /id:' + name + ' /pwd:' + pw + ' /pwdcert:' + cert + ' /autostart') print("Program Initiated...") # 업데이트 대기 print("Waiting for program updates...") time.sleep(20) # 공지사항 창 끄기 appp = pywinauto.Application(backend='uia') def connect_to_appp(appp=appp): appp.connect(path="C:\\Daishin\\CYBOSPLUS\\CpStart.exe") pywinauto.timings.wait_until_passes(60, 1, connect_to_appp) notice = appp.top_window() notice.Button3.click() print("Closed Notice Popup") print("Logged into CreonPlus Successfully") return appp
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 'C:\\中国银河证券双子星3.2\\Binarystar.exe', 默认 'C:\\中国银河证券双子星3.2\\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1) # pylint: disable=broad-except except Exception: self._app = pywinauto.Application().start(exe_path) is_xiadan = True if "xiadan.exe" in exe_path else False # wait login window ready while True: try: self._app.top_window().Edit1.wait("ready") break except RuntimeError: pass code = self._handle_verify_code(is_xiadan) self._app.top_window().Edit1.set_edit_text(user) self.wait(0.1) self._app.top_window().Edit2.set_edit_text(password) self.wait(0.1) while True: edit7 = self._app.top_window().child_window(control_id=1003, class_name="Edit") edit7.set_edit_text(code) self.wait(0.1) self._app.top_window().Button1.click() # detect login is success or not try: self._app.top_window().wait_not("exists visible", 10) break # pylint: disable=broad-except except Exception: if is_xiadan: self._app.top_window().Button1.click() self.wait(0.5) code = self._handle_verify_code(is_xiadan) self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10) self._close_prompt_windows() self._main = self._app.window(title="网上股票交易系统5.0") try: self._main.child_window(control_id=129, class_name="SysTreeView32").wait( "ready", 2) # pylint: disable=broad-except except Exception: self.wait(2) self._switch_window_to_normal_mode()
def login(self, user, password, exe_path, comm_password=None): """ :param user: 用户名 :param password: 密码 :param exe_path: 客户端路径 :param comm_password: :return: """ if comm_password is None: raise ValueError('华泰客户端必须设置通讯密码') try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=0.5) except Exception: self._app = pywinauto.Application().start(exe_path) self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) self._app.top_window().Edit3.type_keys(comm_password) self._app.top_window().type_keys('%Y') # detect login is success or not self._app.top_window().wait_not('exists', 10)
def __init__(self, program_title=None, program_exe=None, ImgPath='img'): """ :param program_title: title name of a window (partial is OK) :param program_exe: path to a program """ if program_exe is not None: app = pywinauto.Application().start( program_exe) # start the program elif program_title is not None: # get the program id and connect to it handle = find_windows(title_re=program_title)[0] app = pywinauto.Application().connect(handle=handle) else: print("Please input program_title or program_exe") sys.exit() if not os.path.exists(ImgPath): os.makedirs(ImgPath) self.ImgPath = './' + ImgPath + '/' self.dlg = app.window( ) # get the window of the program (assume there is only one) self.locs = [] # list of locations to click; order matters self.ratio = 1 #ratio to enlarge/shrink icon
def order(type, code, count, price=0, auto=False): pid = get_pid_by_exec('C:\\同花顺软件\\同花顺\\xiadan.exe') if pid < 0: app = pywinauto.Application(backend="win32").start('C:\\同花顺软件\\同花顺\\xiadan.exe') else: app = pywinauto.Application(backend="win32").connect(process=pid) main_window = app.window(title='网上股票交易系统5.0') if type == 'B': main_window.type_keys('{F2}') main_window.type_keys('{F1}') else: main_window.type_keys('{F1}') main_window.type_keys('{F2}') main_window.type_keys(str(code)) main_window.type_keys('{TAB}') if price > 0: main_window.type_keys(str(price)) main_window.type_keys('{TAB}') main_window.type_keys(str(count)) main_window.type_keys('{TAB}') main_window.type_keys('{ENTER}') if auto: time.sleep(0.5) pywinauto.keyboard.send_keys('{ENTER}') time.sleep(0.5) pywinauto.keyboard.send_keys('{ENTER}')
def login(self, user, password, exe_path): try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1) except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait('ready') break except RuntimeError: pass self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) while True: self._app.top_window().Edit3.type_keys( self._handle_verify_code()) self._app.top_window()['登录'].click() # detect login is success or not try: self._app.top_window().wait_not('exists', 2) break except: pass self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10) self._close_prompt_windows() self._main = self._app.top_window()
def __init__(self, steam_path, sda_path, steam_account: SteamAccount): self.steam_account = steam_account if self.steam_account.check_box and sda_path: try: self.app_sda = pywinauto.Application(backend="win32").connect( path=sda_path) except pywinauto.application.ProcessNotFoundError: self.app_sda = pywinauto.Application( backend="win32").start(sda_path) try: app = pywinauto.Application(backend='win32').connect( path=steam_path) app.kill() except pywinauto.application.ProcessNotFoundError: pass # args = [st_path, "-login", self.steam_account.account_name, self.steam_account.account_pass] # subprocess.call(args) path_with_args = steam_path + f' -login {steam_account.account_name} {steam_account.account_pass}' try: self.app = pywinauto.Application( backend="win32").start(path_with_args) except pywinauto.application.AppStartError: logger.debug('Отсутствует путь до steam.exe')
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ :param user: 用户名 :param password: 密码 :param exe_path: 客户端路径, 类似 :param comm_password: :param kwargs: :return: """ self._editor_need_type_keys = False if comm_password is None: raise ValueError("五矿必须设置通讯密码") try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1) # pylint: disable=broad-except except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait("ready") break except RuntimeError: pass # self.login_test_host = False # if self.login_test_host: # self._app.top_window().type_keys("%t") # self.wait(0.5) # try: # self._app.top_window().Button2.wait('enabled', timeout=30, retry_interval=5) # self._app.top_window().Button5.check() # enable 自动选择 # self.wait(0.5) # self._app.top_window().Button3.click() # self.wait(0.3) # except Exception as ex: # logging.exception("test speed error", ex) # self._app.top_window().wrapper_object().close() # self.wait(0.3) self._app.top_window().Edit1.set_focus() self._app.top_window().Edit1.set_edit_text(user) self._app.top_window().Edit2.set_edit_text(password) self._app.top_window().Edit3.set_edit_text(comm_password) self._app.top_window().Button1.click() # detect login is success or not self._app.top_window().wait_not("exists", 100) self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10) self._close_prompt_windows() self._main = self._app.window(title="网上股票交易系统5.0")
def appCheck(winKey, backEnd, appPath, winTitle): win = [window for window in windows if winKey in str(window)] if win == []: win_app = pywinauto.Application(backend=backEnd).start(appPath) time.sleep(5) else: win_app = pywinauto.Application(backend=backEnd).connect(path=appPath) win_dlg = win_app[winTitle] return win_app, win_dlg
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 r'C:\中国银河证券双子星3.2\Binarystar.exe', 默认 r'C:\中国银河证券双子星3.2\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1) except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait('ready') break except RuntimeError: pass self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) while True: self._app.top_window().Edit3.type_keys( self._handle_verify_code()) self._app.top_window()['登录'].click() # detect login is success or not try: self._app.top_window().wait_not('exists visible', 10) break except: pass self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10) self._shengji = pywinauto.Application().connect( path=self._config.ZDSHENGJI_EXE_PATH).window(title='自动升级') self._xiadan = pywinauto.Application().connect( path=self._config.XIADAN_EXE_PATH, timeout=1) self._close_prompt_windows() self.mclose_shengji() self.mclose_promote() self._main = self._app.window(title='网上股票交易系统5.0') try: self._main.window(control_id=129, class_name='SysTreeView32').wait('ready', 2) except: self._wait(2) self._switch_window_to_normal_mode()
def __init__(self, path=None, precess=None): # 初始化应用程序对象 if path: self.app = pywinauto.Application(backend='uia').start(path) else: self.app = pywinauto.Application(backend='uia').connect( process=precess) # 选择主窗口 self.dlg = self.app['Navicat Premium']
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 'C:\\中国银河证券双子星3.2\\Binarystar.exe', 默认 'C:\\中国银河证券双子星3.2\\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1 ) # pylint: disable=broad-except except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait("ready") break except RuntimeError: pass self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) edit3 = self._app.top_window().window(control_id=0x3eb) while True: try: code = self._handle_verify_code() print(code) edit3.type_keys(code) time.sleep(1) self._app.top_window()["确定(Y)"].click() # detect login is success or not try: self._app.top_window().wait_not("exists", 5) break # pylint: disable=broad-except except Exception: self._app.top_window()["确定"].click() # pylint: disable=broad-except except Exception as e: print(e) pass self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10 ) self._main = self._app.window(title="网上股票交易系统5.0")
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 r'C:\中国银河证券双子星3.2\Binarystar.exe', 默认 r'C:\中国银河证券双子星3.2\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1 ) except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait("ready") break except RuntimeError: pass self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) while True: self._app.top_window().Edit3.type_keys( self._handle_verify_code() ) self._app.top_window()["登录"].click() # detect login is success or not try: self._app.top_window().wait_not("exists visible", 10) break except: pass self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10 ) self._close_prompt_windows() self._main = self._app.window(title="网上股票交易系统5.0") try: self._main.window(control_id=129, class_name="SysTreeView32").wait( "ready", 2 ) except: self.wait(2) self._switch_window_to_normal_mode()
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 'C:\\中国银河证券双子星3.2\\Binarystar.exe', 默认 'C:\\中国银河证券双子星3.2\\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=1) # pylint: disable=broad-except except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait("ready") break except RuntimeError: pass self.type_edit_control_keys(self._app.top_window().Edit1, user) self.type_edit_control_keys(self._app.top_window().Edit2, password) edit3 = self._app.top_window().window(control_id=0x3eb) while True: try: code = self._handle_verify_code() self.type_edit_control_keys(edit3, code) time.sleep(1) self._app.top_window()["用户登录Button"].click() # detect login is success or not try: self._app.top_window().wait_not("exists", 3) break # pylint: disable=broad-except except Exception: self._app.top_window()["确定"].click() # pylint: disable=broad-except except Exception: pass self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=5) self._main = self._app.window(title_re="""{title}""".format( title=self._config.TITLE)) self.close_pop_dialog()
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ :param user: 用户名 :param password: 密码 :param exe_path: 客户端路径, 类似 :param comm_password: :param kwargs: :return: """ if comm_password is None: raise ValueError('华泰必须设置通讯密码') try: self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=2) except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait('ready') break except RuntimeError: pass time.sleep(1) if platform.release() == 'XP': # windows xp系统输入需要延迟等待. xp系统放弃,无法保证输入正确 delaysec = 1 else: delaysec = 0.05 self._app.top_window().Edit1.Click() if (self._app.top_window().Button4.GetCheckState() == 0 or len(self._app.top_window().Edit1.WindowText()) < 8): # 如果有勾选保存账号则跳过输入账号 self._app.top_window().Edit1.type_keys(user) time.sleep(delaysec) self._app.top_window().Edit2.Click() self._app.top_window().Edit2.type_keys(password) time.sleep(delaysec) self._app.top_window().Edit1.Click() self._app.top_window().Edit3.type_keys(comm_password) time.sleep(delaysec) self._app.top_window().button0.click() # detect login is success or not self._app.top_window().wait_not('exists', 10) self._app = pywinauto.Application().connect( path=self._run_exe_path(exe_path), timeout=10) self._close_prompt_windows() self._main = self._app.window(title='网上股票交易系统5.0')
def login(self, user, password, exe_path, comm_password=None, **kwargs): """ 登陆客户端 :param user: 账号 :param password: 明文密码 :param exe_path: 客户端路径类似 r'C:\中国银河证券双子星3.2\Binarystar.exe', 默认 r'C:\中国银河证券双子星3.2\Binarystar.exe' :param comm_password: 通讯密码, 华泰需要,可不设 :return: """ try: self._app = pywinauto.Application().connect(path=self._run_exe_path(exe_path), timeout=1) except Exception: self._app = pywinauto.Application().start(exe_path) # wait login window ready while True: try: self._app.top_window().Edit1.wait('ready') break except RuntimeError: pass self._app.top_window().Edit1.type_keys(user) self._app.top_window().Edit2.type_keys(password) edit3 = self._app.top_window().window(control_id=0x3eb) while True: try: code = self._handle_verify_code() print('verify code=',code) edit3.type_keys( code ) time.sleep(1) self._app.top_window()['确定(Y)'].click() # detect login is success or not try: self._app.top_window().wait_not('exists', 5) break except: self._app.top_window()['确定'].click() pass except Exception as e: print("Exception,",e) pass print('connect start') self._app = pywinauto.Application().connect(path=self._run_exe_path(exe_path), timeout=10) print('connect end') self._main = self._app.window(title='网上股票交易系统5.0')
def connect(self, exe_path=None, **kwargs): """ 直接连接登陆后的客户端 :param exe_path: 客户端路径类似 r'C:\\htzqzyb2\\xiadan.exe', 默认 r'C:\\htzqzyb2\\xiadan.exe' :return: """ connect_path = exe_path or self._config.DEFAULT_EXE_PATH if connect_path is None: raise ValueError( "参数 exe_path 未设置,请设置客户端对应的 exe 地址,类似 C:\\客户端安装目录\\xiadan.exe" ) self._app = pywinauto.Application().connect( path=connect_path, timeout=10 ) self._main = self._app.window_(title_re="网上股票交易系统") self._main.wait('exists enabled visible ready') self._main_handle = self._main.handle self._check_top_window() self._left_treeview = self._main.window_(control_id=129, class_name="SysTreeView32") self._left_treeview.wait('exists enabled visible ready') self._pwindow = self._main.window(control_id=59649, class_name='#32770') self._pwindow.wait('exists enabled visible ready')
def __open_voiceroid2(self, path): # VOICEROID2を起動 # (既に起動済みなら多重起動はされないので考慮とかしない) try: self.__voiceroid2_app = pywinauto.Application().start(path) except pywinauto.application.AppStartError: pass
def controller(file_path, file_name, app_path, saving_path, window_size, step_size): """file_path - path to file in sse extension with file included+watch for path=r""! app_path - path to sse executable saving_path - path to folder for output, / is subsituted for // window and step should contain int in str format""" os.startfile(file_path+file_name) time.sleep(5) app = pw.Application(backend = 'win32').connect(path = app_path) time.sleep(5) while True: try: dlg = app.window(title_re = 'Recover') dlg.type_keys('{TAB}{ENTER}') except pw.findwindows.ElementNotFoundError: break dlg = app.window(title_re="Loading File") app.dlg.type_keys('{ENTER}') time.sleep(5) dlg = app.window(title_re="SSE") dlg.type_keys('{F10}{r}{g}{ENTER}') time.sleep(5) dlg = app.window(title_re="Grouping Scan Parameters") dlg.ComboBox0.select("File") dlg.Edit0.set_text(saving_path) dlg.Edit2.set_text(str(window_size) + "_" + str(step_size) + "_" + str(round(time.time(), 0))[:-2]) dlg.Edit3.set_text("1") dlg.Edit4.set_text("10245") dlg.ComboBox4.select("K2P") dlg.Edit5.set_text("default") dlg.Button16.click() time.sleep(5) dlg = app.window(title_re = "Scan Variables") dlg.Edit1.set_text(window_size) dlg.Edit2.set_text(step_size) dlg.Button3.click()
def main(rdworks_path='RDWorks', is_debug=False, version=1): app = pywinauto.Application(backend='win32') app.process = 1 # hack so next line won't rais AppNotConnected dialog = app.window(title_re='^(Name document|Prompt|RDWorks)$') while True: try: if not app.is_process_running(): app.connect(path=rdworks_path, timeout=10, retry_interval=5) [winsound.Beep(i, 100) for i in range(2000, 5000, 1000)] dialog.wait('enabled', timeout=1, retry_interval=2) if version == 1: dialog.send_keystrokes('{ENTER}{ESC}') elif version == 2: text = dialog.static2.window_text() if text == 'File download success!': winsound.Beep(3000, 1200) # dialog.send_keystrokes('{ESC}') dialog.send_keystrokes('{ESC}') elif text in ('Document name:', 'Duplicate file!Cover the old one?'): # dialog.send_keystrokes('{ENTER}') dialog.send_keystrokes('{ENTER}') else: time.sleep(1) except Exception: if is_debug: raise
def init_window(): try: app = pywinauto.Application().connect(title_re='Roblox') app.Roblox.set_focus() return True except pywinauto.findwindows.ElementNotFoundError: print('Window not found')
def add_windows(self): dsk = pywinauto.Desktop(backend='uia') explorer = pywinauto.Application().connect(path='explorer.exe') self.windows_list.append(explorer.win1) self.windows_list.append(explorer.win2) self.windows_list.append(explorer.win3) self.windows_list.append(explorer.win4)
def wait(self, state: str, timeout: float = 120): """ Pauses until state is reached for all visible windows, timing out in timeout seconds. Useful when waiting for target app to complete execution of a task, or when starting up. Wraps around pywinauto's wait function. :param state: state to wait for ('visible', 'ready', 'exists', 'enabled', 'active') :type state: str :param timeout: Maximum number of seconds to wait for state to be reached. Defaults to a minute, should be longer for apps with more windows. :type timeout: float """ # ---- NOTE: Letting pywinauto handle the errors if state isn't a valid state ---- pids = self.getPIDs() procSecs = timeout / len(pids) success = False # TODO: Change this to use desktop stuff, for the moment this method is the only one I could find that works. # Info: the only types that '.wait()' works on is windowspecifications, and i couldnt find any desktop methods # that return them. Probably because theyre from pywinauto.application.windowspecification, and might only # be 'gettable' from the application class. for pid in pids: try: pywinauto.Application().connect(process=pid).top_window().wait( state, timeout=procSecs) success = True # TODO: Counts as success if one of them works. Reevaluate if this is good or not except: continue if not success: raise WaitException( 'Could not connect to process. Please try again')
def wait_is_ready_try1(wrapper, timeout=120): """ Waits until element is ready (wait while greyed, not enabled, not visible, not ready, ...) : So far, I didn't find better than wait_cpu_usage_lower when greyed but must be enhanced """ t0 = time.time() while not wrapper.is_enabled() or not wrapper.is_visible(): try: h_wait_cursor = win32gui_LoadCursor(0, IDC_WAIT) _, h_cursor, _ = win32gui_GetCursorInfo() app = pywinauto.Application(backend='uia', allow_magic_lookup=False) app.connect(process=wrapper.element_info.element.CurrentProcessId) while h_cursor == h_wait_cursor: app.wait_cpu_usage_lower() spec = app.window(handle=wrapper.handle, top_level_only=False) while not wrapper.is_enabled() or not wrapper.is_visible(): spec.wait("exists enabled visible ready") if (time.time() - t0) > timeout: break except Exception: time.sleep(0.1) pass if (time.time() - t0) > timeout: msg = "Element " + get_wrapper_path(wrapper) + " was not found after " + str(timeout) + " s of searching." raise TimeoutError("Time out! ", msg)
def getWindowObject(appPath): app = pywinauto.Application().connect(path=appPath) #window = app.top_window() allElements = app.window( title_re="NoxPlayer.*") #returns window spec object childWindow = allElements.child_window(title="ScreenBoardClassWindow") return childWindow
def typeIntoSpotifySearch(s): try: import pywinauto import time except ImportError: trace( 'pywinauto is not installed; to enable this feature first install the Python package pywinauto' ) return app = pywinauto.Application() try: app.connect(title_re="Spotify") except pywinauto.WindowNotFoundError: import subprocess subprocess.Popen(['start', 'spotify:'], shell=True) if getInputFromChoices('please wait for spotify to open', ['Spotify is open'])[0] == 0: return typeIntoSpotifySearch(s) return try: sEscaped = s.replace('%', '{%}').replace('^', '{^}').replace('+', '{+}') window = app.top_window_() time.sleep(0.8) window.TypeKeys('^l') time.sleep(0.8) window.TypeKeys(sEscaped, with_spaces=True) time.sleep(0.1) except (pywinauto.WindowNotFoundError, pywinauto.application.AppNotConnected) as exc: trace('exception thrown, ', sys.exc_info()[1])
def login(self): try: self._login() except Exception as e: self.destory() self.app = pywinauto.Application(backend='uia').start(self.path) self._login()
def closing_app(app_path): while True: try: app = pw.Application(backend='win32').connect(path=app_path) app.kill() except pw.application.ProcessNotFoundError: break
def __init__(self, exe_path=r"C:\同花顺软件\同花顺\xiadan.exe"): print("正在连接客户端:", exe_path, "......") self.app = pywinauto.Application().connect(path=exe_path, timeout=10) self.app.grid_strategy: Xls = grid_strategies.Xls print("连接成功!!!") # 等待最多30秒,直到加载data.txt self.main_wnd = self.app.top_window()
def _login_input(self, user_id, norm_pwd, cert_pwd, is_mock): ''' Insert Login information into kiwoom gui login window. :param user_id:[str] kiwoom investor user id :param norm_pwd:[str] normal passward :param cert_pwd:[str] certification passward for real server :param is_mock:[bool] whether you login mock server(True) or not(False) ''' import pywinauto # sys.coinit_flags=0 while True: procs = pywinauto.findwindows.find_elements() for proc in procs: if proc.name == 'Open API Login': break if proc.name == 'Open API Login': break time.sleep(0.1) login_app = pywinauto.Application().connect(process=proc.process_id) login_dig = login_app.OpenAPILogin login_dig.Edit1.send_keystrokes(user_id) login_dig.Edit2.send_keystrokes(norm_pwd) if is_mock: if login_dig.Edit3.is_enabled(): login_dig.Button5.click() # check mock invest server mode login_dig.Edit2.send_keystrokes('{ENTER}') else: if not login_dig.Edit3.is_enabled(): login_dig.Button5.click() # uncheck mock invest server mode login_dig.Button5.uncheck() login_dig.Edit3.send_keystrokes(cert_pwd) login_dig.Edit3.send_keystrokes('{ENTER}') return proc.process_id