示例#1
0
 def untab(self, target):
     if not target:
         raise weberror.CallError(3)
     else:
         if target not in self.tabDict.keys():
             raise weberror.CallError(3)
         else:
             index = self.tabDict[target]
             self.switch_to.window(self.window_handles[index])
             self.execute_script('window.close()')
             self.tabDict.pop(target)
             for key in self.tabDict.keys():
                 if self.tabDict[key] > index:
                     self.tabDict[key] -= 1
def get_website(website, username, password, *args, **kwargs):
    global WEBSITES
    if website not in WEBSITES:
        raise weberror.CallError(4)
    else:
        klass = globals()[website]
        return klass(username, password, *args, **kwargs)
示例#3
0
def get_browser(browser, **kwargs):
    global BROWSERS
    if browser not in BROWSERS:
        raise weberror.CallError(4)
    else:
        klass = globals()['New' + browser]
        return klass(**kwargs)
示例#4
0
 def tab(self, target, arg=None):
     if target is None:
         raise weberror.CallError(3)
     if isinstance(target, int) and target<len(self.tabDict):
         self.switch_to.window(self.window_handles[target])
     else:
         if target not in self.tabDict.keys():
             if not arg:
                 raise weberror.CallError(3)
             else:
                 self.execute_script("window.open('"+arg+"');")
                 index = len(self.tabDict) + 1
                 self.tabDict[target] = index
                 self.switch_to.window(self.window_handles[index])
         else:
             index = self.tabDict[target]
             self.switch_to.window(self.window_handles[index])
示例#5
0
 def wait(self, time=0, ec=None, by=None, elem=None):
     if time == 0:
         return
     elif not ec and not by and not elem:
         sleep(time)
         return
     elif ec and by and elem and time:
         wait = WebDriverWait(self, time)
         by_attr = getattr(BY, by)
         ec_func = getattr(EC, ec)
         result = wait.until(ec_func((by_attr, elem)))
         return result
     else:
         raise weberror.CallError(3)