Beispiel #1
0
 def find(self, findField, findType, index=0):
     element = super().event(findField, findType, index)
     if (element != None):
         return element;
     try:
         if (findType == Executor.Find_id):  # id
             return WebDriverWait(self.getDirver(), timeout).until(lambda x: x.find_element_by_id(findField))
         elif (findType == Executor.Find_ids):  # ids -->[list]
             return WebDriverWait(self.getDirver(), timeout).until(lambda x: x.find_elements_by_id(findField))[index]
         elif (findType == Executor.Find_name):  # name
             return WebDriverWait(self.getDirver(), timeout).until(lambda x: x.find_element_by_name(findField))
         elif (findType == Executor.Find_xpath):  # xpath
             return WebDriverWait(self.getDirver(), timeout).until(lambda x: x.find_element_by_xpath(findField))
         elif (findType == Executor.Find_xpaths):  # xpaths
             return WebDriverWait(self.getDirver(), timeout).until(lambda x: x.find_elements_by_xpath(findField))[
                 index]
         elif (findType == Executor.Find_class):  # class
             elements = WebDriverWait(self.getDirver(), timeout).until(
                 lambda x: x.find_elements_by_class_name(findField))
             return elements.__getitem__(index)
         elif (findType == Executor.Find_css):  # css
             return WebDriverWait(self.getDirver(), timeout).until(
                 lambda x: x.find_element_by_css_selector(findField))
     except selenium.common.exceptions.TimeoutException:  # 超时
         return None
     except selenium.common.exceptions.NoSuchElementException:  # 不存在
         return None
     except Exception as e:
         print(e)
         return None