Пример #1
0
 def cards(self, combo, i, ii):
     while 1:
         try:
             self.stemTwoinitControl()
             data = self.getInputData(i, ii)
             card1 = data.get("卡号1")
             self._log.info(f"获得到的卡1数据是>>: {card1}")
             base_name = combo.GetSelectionPattern().GetSelection()[0].Name
             if len(re.compile(card1).findall(base_name)) != 0:
                 self._log.info(f'以选择案例卡号>: {base_name}')
             else:
                 combo.Click()
             card_id_list = [
                 i for i in combo.GetChildren()
                 if i.ClassName == 'ListBoxItem' and i.Name
             ]
             for card_id in card_id_list:
                 if len(re.compile(card1).findall(card_id.Name)) != 0:
                     combo.Select(card_id.Name)
             break
         except Exception as e:
             tab = auto.TabControl(AutomationId='mainTab').TabItemControl(
                 Name="emd.ViewModel.ColGridViewModel")
             tab.DoubleClick()
             auto.PaneControl(
                 AutomationId='scroll').GetScrollPattern().SetScrollPercent(
                     horizontalPercent=-1, verticalPercent=100)
             self._log.error(f"卡号对象消失,正在重新查找,报错信息为{e}")
             continue
Пример #2
0
 def input_text(self, field, message, num):
     while 1:
         try:
             search = auto.EditControl(AutomationId='SearchFrame')
             search.SendKeys('{Ctrl}a{Delete}')
             self._log.info('搜索字段:{}'.format(field))
             search.SendKeys(field + '{Enter}')
             try:
                 fieldInput = self._CaseShowTwoPO.getTab6()(
                     Name=field).GetParentControl().GetChildren()[2]
                 fieldInput.DoubleClick()
                 time.sleep(self.clickout)
                 send = fieldInput.EditControl()
                 self._log.info('填写字段:{}-->{}'.format(field, message))
                 send.SendKeys('{Ctrl}a{Delete}')
                 send.SendKeys(message + '{Enter}')
             except LookupError:
                 self._log.error('案例序号:{},字段:{},名称有误,请检查'.format(
                     num, field))
                 return False, field
             break
         except Exception as e:
             tab = auto.TabControl(AutomationId='mainTab').TabItemControl(
                 Name='emd.ViewModel.ColGridViewModel')
             tab.DoubleClick()
             self._log.error(f"输入对象丢失,正在重新查找,报错信息为{e}")
             continue
Пример #3
0
 def SaveButton(self):
     while 1:
         try:
             locating = auto.DataGridControl(
                 AutomationId='DataGrid1').HeaderControl(
                 ).HeaderItemControl().TextControl()
             locating_x = locating.GetClickablePoint()[0]
             locating_y = locating.GetClickablePoint()[1] - 40
             auto.Click(locating_x, locating_y)
             self._log.info(f"点击保存按钮")
             break
         except Exception as e:
             tab = auto.TabControl(AutomationId='mainTab').TabItemControl(
                 Name='emd.ViewModel.ColGridViewModel')
             tab.DoubleClick()
             self._log.error(f"输入对象丢失,正在重新查找,报错信息为{e}")
             continue
Пример #4
0
 def rootCardInfo(self):
     while 1:
         try:
             group = auto.GroupControl(Name='账号基本信息').GetChildren()
             combo = group[2]
             break
         except:
             tab = auto.TabControl(AutomationId='mainTab').TabItemControl(
                 Name='emd.ViewModel.ColGridViewModel')
             tab.DoubleClick()
             continue
     try:
         auto.PaneControl(
             AutomationId='scroll').GetScrollPattern().SetScrollPercent(
                 horizontalPercent=-1, verticalPercent=100)
         self._log.info(f"滚动到选择卡号的位置")
     except:
         pass
     return combo
def main():
    firefoxWindow = automation.WindowControl(searchDepth = 1, ClassName = 'MozillaWindowClass')
    if not firefoxWindow.Exists(0):
        automation.Logger.WriteLine('please run Firefox first', automation.ConsoleColor.Yellow)
        return
    firefoxWindow.ShowWindow(automation.ShowWindow.Maximize)
    firefoxWindow.SetActive()
    time.sleep(1)
    tab = automation.TabControl(searchFromControl= firefoxWindow)
    newTabButton = automation.ButtonControl(searchFromControl= tab, searchDepth= 1)
    newTabButton.Click()
    edit = automation.EditControl(searchFromControl= firefoxWindow)
    # edit.Click()
    edit.SendKeys('http://global.bing.com/?rb=0&setmkt=en-us&setlang=en-us{Enter}')
    time.sleep(2)
    searchEdit = automation.FindControl(firefoxWindow,
                           lambda c:
                           (isinstance(c, automation.EditControl) or isinstance(c, automation.ComboBoxControl)) and c.Name == 'Enter your search term'
                           )
    # searchEdit.Click()
    searchEdit.SendKeys('Python-UIAutomation-for-Windows site:github.com{Enter}', 0.05)
    link = automation.HyperlinkControl(searchFromControl= firefoxWindow, SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    automation.Win32API.PressKey(automation.Keys.VK_CONTROL)
    link.Click()  #press control to open the page in a new tab
    automation.Win32API.ReleaseKey(automation.Keys.VK_CONTROL)
    newTab = automation.TabItemControl(searchFromControl= tab, SubName = 'yinkaisheng/Python-UIAutomation-for-Windows')
    newTab.Click()
    starButton = automation.ButtonControl(searchFromControl= firefoxWindow, Name = 'Star this repository')
    if starButton.Exists(5):
        automation.GetConsoleWindow().SetActive()
        automation.Logger.WriteLine('Star Python-UIAutomation-for-Windows after 2 seconds', automation.ConsoleColor.Yellow)
        time.sleep(2)
        firefoxWindow.SetActive()
        time.sleep(1)
        starButton.Click()
        time.sleep(2)
Пример #6
0
    def find(self, ControlTypeName="Control", **kwargs):

        if ControlTypeName == "Control":
            control = auto.Control(**kwargs)

        if ControlTypeName == "ButtonControl":
            control = auto.ButtonControl(**kwargs)

        if ControlTypeName == "CalendarControl":
            control = auto.CalendarControl(**kwargs)

        if ControlTypeName == "CheckBoxControl":
            control = auto.CheckBoxControl(**kwargs)

        if ControlTypeName == "ComboBoxControl":
            control = auto.ComboBoxControl(**kwargs)

        if ControlTypeName == "CustomControl":
            control = auto.CustomControl(**kwargs)

        if ControlTypeName == "DataGridControl":
            control = auto.DataGridControl(**kwargs)

        if ControlTypeName == "DataItemControl":
            control = auto.DataItemControl(**kwargs)

        if ControlTypeName == "DocumentControl":
            control = auto.DocumentControl(**kwargs)

        if ControlTypeName == "EditControl":
            control = auto.EditControl(**kwargs)

        if ControlTypeName == "GroupControl":
            control = auto.GroupControl(**kwargs)

        if ControlTypeName == "HeaderControl":
            control = auto.HeaderControl(**kwargs)

        if ControlTypeName == "HeaderItemControl":
            control = auto.HeaderItemControl(**kwargs)

        if ControlTypeName == "HyperlinkControl":
            control = auto.HyperlinkControl(**kwargs)

        if ControlTypeName == "ImageControl":
            control = auto.ImageControl(**kwargs)

        if ControlTypeName == "ListControl":
            control = auto.ListControl(**kwargs)

        if ControlTypeName == "ListItemControl":
            control = auto.ListItemControl(**kwargs)

        if ControlTypeName == "MenuControl":
            control = auto.MenuControl(**kwargs)

        if ControlTypeName == "MenuBarControl":
            control = auto.MenuBarControl(**kwargs)

        if ControlTypeName == "MenuItemControl":
            control = auto.MenuItemControl(**kwargs)

        if ControlTypeName == "PaneControl":
            control = auto.PaneControl(**kwargs)

        if ControlTypeName == "ProgressBarControl":
            control = auto.ProgressBarControl(**kwargs)

        if ControlTypeName == "RadioButtonControl":
            control = auto.RadioButtonControl(**kwargs)

        if ControlTypeName == "ScrollBarControl":
            control = auto.ScrollBarControl(**kwargs)

        if ControlTypeName == "SemanticZoomControl":
            control = auto.SemanticZoomControl(**kwargs)

        if ControlTypeName == "SeparatorControl":
            control = auto.SeparatorControl(**kwargs)

        if ControlTypeName == "SliderControl":
            control = auto.SliderControl(**kwargs)

        if ControlTypeName == "SpinnerControl":
            control = auto.SpinnerControl(**kwargs)

        if ControlTypeName == "SplitButtonControl":
            control = auto.SplitButtonControl(**kwargs)

        if ControlTypeName == "StatusBarControl":
            control = auto.StatusBarControl(**kwargs)

        if ControlTypeName == "TabControl":
            control = auto.TabControl(**kwargs)

        if ControlTypeName == "TabItemControl":
            control = auto.TabItemControl(**kwargs)

        if ControlTypeName == "TextControl":
            control = auto.TextControl(**kwargs)

        if ControlTypeName == "ThumbControl":
            control = auto.ThumbControl(**kwargs)

        if ControlTypeName == "TitleBarControl":
            control = auto.TitleBarControl(**kwargs)

        if ControlTypeName == "ToolBarControl":
            control = auto.ToolBarControl(**kwargs)

        if ControlTypeName == "ToolTipControl":
            control = auto.ToolTipControl(**kwargs)

        if ControlTypeName == "TreeControl":
            control = auto.TreeControl(**kwargs)

        if ControlTypeName == "TreeItemControl":
            control = auto.TreeItemControl(**kwargs)

        if ControlTypeName == "WindowControl":
            control = auto.WindowControl(**kwargs)

        if control.Exists():
            return control
        else:
            name = kwargs.__str__().replace(":", ":")
            Log.logger().error("元素查找失败%s" % name)
            autogui.screenshot("../log/%s.png" % name)