Exemplo n.º 1
0
    def Url(self):
        '''返回当前的URL地址
        '''
        qpstr = "/classname='WorkerW' && visible='True' /classname='ReBarWindow32' \
        /classname~='(Address|ComboBox)' && Instance='0' /maxdepth='3' && classname='Edit'"

        addr_edit = win32.Control(root=self, locator=QPath(qpstr))
        return addr_edit.Caption
Exemplo n.º 2
0
    def search(self, root=None):
        """根据qpath和root查找控件
        
        :type root: 实例类型
        :param root:  查找开始的控件
        :return: 返回找到的控件列表
        """

        if root is None:
            root = wincontrols.Control()  # desktop Control
        controls, self._error_qpath = self._find_controls_recur(
            root, self._parsed_qpath)
        return controls
Exemplo n.º 3
0
    def __init__(self, process_id):
        '''初始化,进程id

        :params process_id: 窗口进程id
        :type process_id: int
        '''
        self._pid = process_id
        qpstr = "|classname='IEFrame' && visible='True'|classname='WorkerW' && visible='True'\
        |classname='ReBarWindow32' |classname='Address Band Root' && Instance='0' |maxdepth='3' && classname='Edit' && ProcessId='%d'" % process_id
        old_timeout = win32.Control._timeout
        win32.Control._timeout = self._timeout
        addr_edit = win32.Control(locator=QPath(qpstr))
        win32gui.BringWindowToTop(addr_edit.TopLevelWindow.HWnd)  # 激活ie窗口,并显示在最前端
        win32.Control._timeout = old_timeout
        win32.Window.__init__(self, root=addr_edit.TopLevelWindow)
        # 实现窗口最大化的逻辑
        time.sleep(0.005)  # 优化最大化的视觉效果
Exemplo n.º 4
0
    def ie_window(self):
        '''获取Internet Explorer_Server对应的ie窗口
        '''
        iever = IEBrowser.get_version()
        iever = int(iever.split('.')[0])
        if iever < 6:
            raise RuntimeError("不支持IE%s" % iever)
        elif iever == 6:  # ie6
            qp = QPath("/classname='Shell DocObject View' && visible='True'/classname='Internet Explorer_Server'")
        elif iever == 7:
            qp = QPath("/classname='TabWindowClass' && visible='True'/maxdepth='3' && classname='Internet Explorer_Server'")
        else:
            qp = QPath("/classname='Frame Tab' && visible='True'/maxdepth='3' && classname='Internet Explorer_Server'")

        ie_window = win32.Control(root=self, locator=qp)
        ie_window._timeout = self._timeout
        ie_window.HWnd
        return ie_window
Exemplo n.º 5
0
 def __init__(self, hwnd):
     '''Constructor
     
     :param hwnd: 需要同步消息的窗口
     '''
     import qt4c.wincontrols as win
     import qt4c.qpath as qpath
     
     self._syncwnd = 0
     self._eventobj = 0
             
     wndobj = win.Control(root=hwnd)
     try:
         self._pid = wndobj.ProcessId
     except win32gui.error as e:
         if e.winerror == winerror.ERROR_INVALID_WINDOW_HANDLE: #invalid hwnd
             return
         else:
             raise e
     if self._pid == 0: #窗口消失,获取pid为0
         return
     
     if self._pid in MsgSyncer.pid_event_map:
         self._syncwnd, self._eventobj = MsgSyncer.pid_event_map[self._pid]
     else:
         qp = qpath.QPath("/classname='AssistWnd' && processid='%d'" % self._pid)
         wnds = qp.search(None)
         if len(wnds) >1 :
             raise RuntimeError("在一个进程中发现两个SyncWnd")
         elif len(wnds) == 1:
             self._syncwnd = wnds[0].HWnd
             self._eventobj = win32event.CreateEvent(None, True, False, "Event_Sync_%d" % self._pid)
             MsgSyncer.pid_event_map[self._pid] = (self._syncwnd, self._eventobj)
         else:
             import testbase.logger as logger
             logger.debug("Cannot find AssistWnd(%s)" % qp)