示例#1
0
def Rdp_Action_once(ip, passwd, acount, cmd):
    #启动RDP.exe
    app_startcmd = RDP_Path + " /f" + " /v:" + ip + " /u:" + acount + " /p:" + passwd
    print(app_startcmd)
    app = Application().start(app_startcmd)
    time.sleep(25)
    #RDP_con = Application().connect(title_re=".*远程桌面连接").top_window()
    RDP_con = Application().connect(
        class_name="TscShellContainerClass").top_window()
    #win10登录需点击、输入回车
    #pywinauto.mouse.click(button='left', coords=(160, 160))
    time.sleep(2)
    RDP_con.type_keys('{VK_RETURN}')
    #进入界面
    time.sleep(8)
    RDP_con = Application().connect(
        class_name="TscShellContainerClass").top_window()
    #RDP_con = Application().connect(title_re=".*远程桌面连接").top_window()
    time.sleep(1.5)
    RDP_con.print_control_identifiers()
    #模拟输入win+R
    RDP_con.type_keys('{VK_RWIN}')
    #输入cmd
    time.sleep(1.5)
    RDP_con.type_keys('powershell')
    time.sleep(2.5)
    RDP_con.type_keys('{VK_RETURN}')
    time.sleep(4.5)
    RDP_con.type_keys((cmd))
    print((cmd))
    time.sleep(0.5)
    RDP_con.type_keys('{VK_RETURN}')
    time.sleep(33.5)
    RDP_con.close()
示例#2
0








#%%
app_menu = app.top_window().descendants(control_type="MenuBar")
app_menu.children()


app.ProcessingVelox.Menu.print_control_identifiers()
app.print_control_identifiers()#['menu bar']['File Alt+F']#.get_items()#['Open... Ctrl+O']
#%%
#app = Application(backend="win32").connect(handle=0x540D12)

dialogs = app.windows()
#print(dialogs)

app['Beam Settings']['TEM'].click()

# scrollbar click 0 (up) 1 (down)
app.Stigmator.Stigmator_main.ScrollBar1.click()

app.Stigmator.Stigmator_main.Diffraction.click()
#app.Stigmator.Stigmator_main.print_control_identifiers()

#app.Stigmator.Objective.click()
示例#3
0
def find_window(backend, obj, level, dict, traces):

    success = True

    for loop_x in range(0, len(dict)):
        try:
            temp_list = dict[str(loop_x + 1)].split(",")

            name = None
            process = None
            handle = None
            path = None
            class_name = None
            class_name_re = None
            title = None
            title_re = None
            control_id = None
            control_type = None
            auto_id = None
            framework_id = None

            for loop_y in range(0, len(temp_list)):

                if "name=" in str(temp_list[loop_y]).strip():
                    name = str(temp_list[loop_y]).strip()
                    name = name[5:]

                elif "process=" in str(temp_list[loop_y]).strip():
                    process = str(temp_list[loop_y]).strip()
                    process = process[8:]

                elif "handle=" in str(temp_list[loop_y]).strip():
                    handle = str(temp_list[loop_y]).strip()
                    handle = handle[7:]

                elif "path=" in str(temp_list[loop_y]).strip():
                    path = str(temp_list[loop_y]).strip()
                    path = path[5:]

                elif "class_name=" in str(temp_list[loop_y]).strip():
                    class_name = str(temp_list[loop_y]).strip()
                    class_name = class_name[11:]

                elif "class_name_re=" in str(temp_list[loop_y]).strip():
                    class_name_re = str(temp_list[loop_y]).strip()
                    class_name_re = class_name_re[14:]

                elif "title=" in str(temp_list[loop_y]).strip():
                    title = str(temp_list[loop_y]).strip()
                    title = title[6:]

                elif "title_re=" in str(temp_list[loop_y]).strip():
                    title_re = str(temp_list[loop_y]).strip()
                    title_re = title_re[9:]

                elif "control_id=" in str(temp_list[loop_y]).strip():
                    control_id = str(temp_list[loop_y]).strip()
                    control_id = control_id[11:]

                elif "control_type=" in str(temp_list[loop_y]).strip():
                    control_type = str(temp_list[loop_y]).strip()
                    control_type = control_type[13:]

                elif "auto_id=" in str(temp_list[loop_y]).strip():
                    auto_id = str(temp_list[loop_y]).strip()
                    auto_id = auto_id[8:]

                elif "framework_id=" in str(temp_list[loop_y]).strip():
                    framework_id = str(temp_list[loop_y]).strip()
                    framework_id = framework_id[13:]

            if level == "app":
                if path is not None:
                    obj = Application(backend=backend).connect(path=path)
                elif handle is not None:
                    obj = Application(backend=backend).connect(handle=handle)
                elif process is not None:
                    obj = Application(backend=backend).connect(process=process)
                elif title_re is not None:
                    obj = Application(backend=backend).connect(
                        title_re=title_re)
                else:
                    obj = Application(backend=backend).connect(title=title)

                try:
                    success = obj.is_process_running()
                except:
                    success = False
                    break

            else:
                if level == "main":
                    if name is not None:
                        obj = obj[name]

                    elif backend == "uia":
                        obj = obj.window(class_name=class_name,
                                         class_name_re=class_name_re,
                                         title=title,
                                         title_re=title_re,
                                         control_id=control_id,
                                         control_type=control_type,
                                         auto_id=auto_id,
                                         framework_id=framework_id)
                    else:
                        obj = obj.window(class_name=class_name,
                                         class_name_re=class_name_re,
                                         title=title,
                                         title_re=title_re,
                                         control_id=control_id,
                                         control_type=control_type)

                else:
                    if name is not None:
                        obj = obj[name]

                    elif backend == "uia":
                        obj = obj.child_window(class_name=class_name,
                                               class_name_re=class_name_re,
                                               title=title,
                                               title_re=title_re,
                                               control_id=control_id,
                                               control_type=control_type,
                                               auto_id=auto_id,
                                               framework_id=framework_id)
                    else:
                        obj = obj.child_window(class_name=class_name,
                                               class_name_re=class_name_re,
                                               title=title,
                                               title_re=title_re,
                                               control_id=control_id,
                                               control_type=control_type)

                if traces is True:
                    try:
                        trace_str = level

                        if level is not "main":
                            trace_str = trace_str + " " + str(loop_x + 1)

                        print("")
                        print(datetime.datetime.now().strftime(
                            '%Y-%m-%d %H:%M:%S') + ": " + "\t=== * Locating " +
                              trace_str + " start * ===")
                        print("")
                        obj.print_control_identifiers(depth=1)
                        print("")
                        print(datetime.datetime.now().strftime(
                            '%Y-%m-%d %H:%M:%S') + ": " + "\t=== * Locating " +
                              trace_str + " end * ===")
                        print("")

                    except:
                        if level == "main":
                            print(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S') + ": " +
                                  "\tUNABLE TO LOCATE MAIN WINDOW!")
                        else:
                            print(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S') + ": " +
                                  "\tUNABLE TO LOCATE CHILD WINDOW " +
                                  str(loop_x + 1) + "!")
                        success = False
                        break

                if not obj.exists():
                    success = False
                    break

        except:
            print(traceback.format_exc())
            success = False
            break

    if success is True:
        return obj
    else:
        return None
示例#4
0
class ControlApp:
    def __init__(self):
        self.appName = 'notepad.exe'
        # self.appName = r'C:\Program Files\Windows NT\Accessories\wordpad.exe'

    def startApp(self):
        self.app = Application().start(self.appName)

    def demoNotepad(self):
        self.app.UntitledNotepad.menu_select('帮助(&H)->关于记事本(&A)')
        sleep(2)
        ABOUT = u'关于“记事本”'
        OK = u'确定'
        self.app[ABOUT][OK].click()

        fileName = 'test7.txt'

        self.app.UntitledNotepad.Edit.type_keys(
            'pywinauto Works! \n\n ', with_spaces=True,
            with_newlines=True)  # 在记事本窗口中写入内容,并换行
        self.app.UntitledNotepad.Edit.type_keys('第二行中文字符串',
                                                with_spaces=True,
                                                with_newlines=True)
        sleep(2)
        self.app['无标题-记事本'].MenuSelect('文件->另存为...')  # 打开记事本的另存为窗口
        self.app['另存为']['edit'].TypeKeys(fileName)  # 将文件名键入
        self.app['另存为']['保存'].click()  # 更改文件名之后保存

        self.app.UntitleNotepad.menu_select('文件->退出')  # 选择菜单退出

    def demoWordpad(self):
        self.app.wordpadclass.RICHEDIT50W.type_keys('this is wordpad.exe',
                                                    with_spaces=True,
                                                    with_newlines=True)

        sleep(1)
        self.app.wordpadclass.RICHEDIT50W.TypeKeys('^a')
        sleep(1)
        self.app.wordpadclass.RICHEDIT50W.RightClickInput(coords=(500, 100))
        sleep(1)
        self.app.wordpadclass.RICHEDIT50W.ClickInput(coords=(550, 150))
        self.app.wordpadclass.RICHEDIT50W.TypeKeys('^s')

        fileName = 'test6.rtf'
        # self.app['文档-写字板'].MenuSelect('文件->另存为...')  # 打开写字板的另存为窗口
        # self.app['另存为']['edit'].TypeKeys(fileName)  # 将文件名键入
        # self.app['另存为']['保存'].click()  # 更改文件名之后保存
        # self.app.wordpadclass.menu_select('文件->退出')  # 选择菜单退出
        # self.app['记事本']['保存'].click()  # 保存写好的记事本

        saveDlg = self.app.window(title_re=u'保存为', class_name='#32770')
        saveDlg.edit.TypeKeys(u'D:\\' + fileName)
        self.app[u'保存为'][u'保存(S)'].SetFocus()
        self.app[u'保存为'][u'保存(S)'].Click()

    def demoClass(self):
        self.app.Notepad.menu_select('帮助->关于记事本')

        about_dlg = self.app.window(title_re=u'关于', class_name='#32770')  #
        print('-' * 10, 'identifiers start', '-' * 10, '\n')
        about_dlg.print_control_identifiers()
        print('-' * 10, 'identifiers finish', '-' * 10, '\n')
        self.app.window(title_re=u'关于“记事本”').window(title_re=u'确定').Click()
        sleep(.5)

    def printIdent(self):
        self.app.print_control_identifiers()