コード例 #1
0
 def waitElementtobelocated(self, by, locator):
     """显示等待某个元素出现,且可见"""
     print('info:waiting "{}" to be located'.format(locator))
     try:
         wd(self.driver, self.outTime).until(EC.visibility_of_element_located((self.byDic[by], locator)))
     except TimeoutException as t:
         print('error: found "{}" timeout!'.format(locator), t)
     except NoSuchWindowException as e:
         print('error: no such "{}"'.format(locator), e)
     except Exception as e:
         raise e
コード例 #2
0
 def switch_to_frame(self,by,locator):
     '''
     判断frame是否存在,存在就跳到frame
     :param by:
     :param locator:
     :return:
     '''
     print('info:switching to iframe "{}"'.format(locator))
     if by.lower() in self.byDic:
         try:
             wd(self.driver, self.outTime).until(ec.frame_to_be_available_and_switch_to_it(self.byDic[by], locator))
         except TimeoutException as t:
             print('error: found "{}" timeout!切换frame失败'.format(locator), t)
     else:
         print('the "{}" error!'.format(by))
コード例 #3
0
 def switchToFrame(self, by, locator):
     """判断frame是否存在,存在就跳到frame"""
     print('info:switching to iframe "{}"'.format(locator))
     if by.lower() in self.byDic:
         try:
             wd(self.driver, self.outTime).\
                 until(EC.frame_to_be_available_and_switch_to_it((self.byDic[by], locator)))
         except TimeoutException as t:
             print('error: found "{}" timeout!'.format(locator), t)
         except NoSuchFrameException as e:
             print('error: no such "{}"'.format(locator), e)
         except Exception as e:
             raise e
     else:
         print('the "{}" error!'.format(by))
コード例 #4
0
 def wait_element_to_be_located(self, by, locator):
     """显示等待某个元素出现,且可见"""
     print('info:waiting "{}" to be located'.format(locator))
     try:
         return wd(self.driver, self.outTime).until(ec.presence_of_element_located((self.byDic[by], locator)))
     except TimeoutException as t:
         print('error: found "{}" timeout!'.format(locator), t)
コード例 #5
0
 def is_element_exist(self,by,locator):
     '''
     assert element if exist
     :param by: id,name,xpath ,css......
     :param locator: eg:id,name,xpath for str
     :return: if element return True else return false
     '''
     if by.lower() in self.byDic:
         try:
             wd(self.driver,self.outTime).until(ec.invisibility_of_element_located(self.byDic[by],locator))
         except TimeoutException as t:
             print('error:found "{}" timeout !'.format(locator), t)
             return False
         except NoSuchWindowException as e:
             print('error:no such "{}" '.format(locator), e)
             return False
         return True
     else:
         print('the "{}" error!'.format(by))
コード例 #6
0
 def isElementExsit(self, by, locator):
     """
     assert element if exist
     :param by: eg: id, name, xpath, css.....
     :param locator: eg: id, name, xpath for str
     :return: if element return True else return false
     """
     if by.lower() in self.byDic:
         try:
             wd(self.driver, self.outTime).\
                 until(EC.visibility_of_element_located((self.byDic[by], locator)))
         except TimeoutException:
             print('Error: element "{}" time out!'.format(locator))
             return False
         except NoSuchWindowException:
             print('Error: element "{}" not exsit!'.format(locator))
             return False
         return True
     else:
         print('the "{}" error!'.format(by))
コード例 #7
0
 def isClick(self, by, locator):
     """判断是否可点击,返回元素对象"""
     if by.lower() in self.byDic:
         try:
             element = wd(self.driver, self.outTime).\
                 until(EC.element_to_be_clickable((self.byDic[by], locator)))
         except Exception:
             return False
         return element
     else:
         print('the "{}" error!'.format(by))
コード例 #8
0
 def is_alert(self):
     '''
     assert alsrt if exsit
     :return:alert obj
     '''
     try:
         re = wd(self.driver,self.outTime).until(ec.alert_is_present())
     except (TimeoutException,NoAlertPresentException):
         print('error:no found alert')
     else:
         return re
コード例 #9
0
 def isAlertAndSwitchToIt(self):
     """
     assert alert if exsit
     :return: alert obj
     """
     try:
         re = wd(self.driver, self.outTime).until(EC.alert_is_present())
     except NoAlertPresentException:
         return False
     except Exception:
         return False
     return re
コード例 #10
0
 def is_click(self,by,locator):
     '''
     判断是否可点击 没返回元素对象
     :param by:
     :param locator:
     :return:
     '''
     if by.lower() in self.byDic:
         try:
             element = wd(self.driver, self.outTime).until(ec.element_to_be_clickable(self.byDic[by], locator))
         except TimeoutException:
             print('元素不可以点击')
         else:
             return element
     else:
         print('the "{}" error!'.format(by))
コード例 #11
0
 def find_elements(self,by,locator):
     '''
     find group elements
     :param by:
     :param locator:
     :return: elements object
     '''
     try:
         print('[Info:Had found the elements "{}" by "{}" !]'.format(locator,by))
         elements = wd(self.driver,self.outTime).until(lambda x:x.find_element(by,locator))
     except TimeoutException as t:
         print('error:found "{}" timeout !'.format(locator),t)
     except NoSuchWindowException as e:
         print('error:no such "{}" '.format(locator),e)
     except Exception as e:
         raise e
     else:
         return elements
コード例 #12
0
 def findElements(self, by, locator):
     """
     find group elements
     :param by: eg: id, name, xpath, css.....
     :param locator: eg: id, name, xpath for str
     :return: elements object
     """
     try:
         print('[Info:start find the elements "{}" by "{}"!]'.format(locator, by))
         elements = wd(self.driver, self.outTime).until(lambda x : x.find_element(by, locator))
     except TimeoutException as t:
         print(t)
     except NoSuchWindowException as e:
         print(e)
     except Exception as e:
         raise e
     else:
         # print('[Info:Had found the elements "{}" by "{}"!]'.format(locator, by))
         return elements
コード例 #13
0
 def findElement(self, by, locator):
     """
     find alone element
     :param by: eg: id, name, xpath, css.....
     :param locator: id, name, xpath for str
     :return: element object
     """
     try:
         print('[Info:Starting find the element "{}" by "{}"!]'.format(locator, by))
         element = wd(self.driver, self.outTime).until(lambda x : x.find_element(by, locator))
     except TimeoutException as t:
         print('error: found "{}" timeout!'.format(locator), t)
     except NoSuchWindowException as e:
         print('error: no such "{}"'.format(locator), e)
     except Exception as e:
         raise e
     else:
         # print('[Info:Had found the element "{}" by "{}"!]'.format(locator, by))
         return element