Exemple #1
0
 def get_element(self, key, section=None):
     read_ini = ReadIni()
     local = read_ini.get_value(key, section=section)
     if local != None:
         by = local.split('>')[0]
         local_by = local.split('>')[1]
         try:
             if by == 'id':
                 return self.driver.find_element_by_id(local_by)
             elif by == 'className':
                 return self.driver.find_element_by_class_name(local_by)
             elif by == 'accessibility_id':
                 return self.driver.find_element_by_accessibility_id(
                     local_by)
             elif by == 'accessibility_ids':
                 return self.driver.find_elements_by_accessibility_id(
                     local_by)
             elif by == 'android_uiautomator':
                 return self.driver.find_element_by_android_uiautomator(
                     local_by)
             elif by == 'android_uiautomators':
                 return self.driver.find_elements_by_android_uiautomator(
                     local_by)
             elif by == 'ids':
                 return self.driver.find_elements_by_id(local_by)
             elif by == 'xpath':
                 return self.driver.find_element_by_xpath(local_by)
             elif by == 'classNames':
                 return self.driver.find_elements_by_class_name(local_by)
             else:
                 return self.driver.find_element_by_xpath(local_by)
         except:
             return None
     else:
         return None
Exemple #2
0
    def get_element(self, section, key):
        read_ini = ReadIni()
        local = read_ini.get_value(section, key)
        if local is not None:
            by = local.split(">")[0]
            local_by = local.split(">")[1]
            try:
                if by == "id":
                    return self.driver.find_element_by_id(local_by)

                elif by == "class_name":
                    return self.driver.find_element_by_class_name(local_by)

                else:
                    return self.driver.find_element_by_xpath(local_by)

            except:
                # seed = int(random.random() * 1000)
                # now = time.strftime('%Y-%m-%d %H_%M_%S')
                # screenshotName = "./screenshots/" + now + "Seed" + str(seed) + ".png"
                # print("screenshotName:", screenshotName.split('./screenshots/')[1])
                # self.driver.save_screenshot(screenshotName)
                return None

        else:
            return None
Exemple #3
0
class GetByLocal:
    def __init__(self,driver):
        self.driver = driver
        self.readini = ReadIni()

    def get_element(self,section,key):
        local = self.readini.get_value(section,key)
        local_by = local.split('>')[0]
        local_value = local.split('>')[1]
        if local_by == 'id':
            return self.driver.find_element_by_id(local_value)
        elif local_by == 'className':
            return self.driver.find_element_by_class_name(local_value)
        elif local_by == 'xpath':
            return self.driver.find_element_by_xpath(local_value)
        elif local_by == 'ANUItext':
            return self.driver.find_element_by_android_uiautomator('new UiSelector().text("'+local_value+'")')
        elif local_by == 'ANUIstext':
            return self.driver.find_elements_by_android_uiautomator('new UiSelector().text("'+local_value+'")')
        elif local_by == 'classNames':
            if len(local.split('>')) > 2:
                return self.driver.find_elements_by_class_name(local_value)[int(local.split('>')[2])]
            else:
                return self.driver.find_elements_by_class_name(local_value)
        elif local_by =='ANUIcontent-desc':
            return self.driver.find_element_by_android_uiautomator('new UiSelector().description("'+local_value+'")')
        elif local_by == 'ids':
            if len(local.split('>')) > 2:
                return self.driver.find_elements_by_id(local_value)[int(local.split('>')[2])]
            else:
                return self.driver.find_elements_by_id(local_value)
        elif local_by == 'toast':
            return local_value
        else:
            return None
    def get_locator(self,section,key):
        local = self.readini.get_value(section,key)
        local_by = local.split('>')[0]
        local_value = local.split('>')[1]
        if local_by == 'id':
            locator = (By.ID,local_value)
        elif local_by == 'className':
            locator = (By.CLASS_NAME, local_value)
        elif local_by == 'xpath':
            locator = (By.XPATH, local_value)
        elif local_by == 'cssSelector':
            locator = (By.CSS_SELECTOR, local_value)
        elif local_by == 'linkText':
            locator = (By.LINK_TEXT, local_value)
        elif local_by == 'partialLinkText':
            locator = (By.PARTIAL_LINK_TEXT, local_value)
        elif local_by == 'tagName':
            locator = (By.TAG_NAME, local_value)
        else:
            locator =  None

        return locator
 def get_element(self,
                 key,
                 package_name='com.nexttao.shopforce.enterprise',
                 file_path='../config/login.ini',
                 section=None):
     read_ini = ReadIni(file_path)
     local = read_ini.get_value(key, section)
     if 'By.ID' in local:
         local = local % package_name
     return local
 def get_element(self, key):
     read_ini = ReadIni()
     data = read_ini.get_value(key)
     by = data.split('>')[0]
     value = data.split('>')[1]
     try:
         if by == 'id':
             return self.driver.find_element_by_id(value)
         elif by == 'className':
             return self.driver.find_element_by_class_name(value)
     except:
         return None
Exemple #6
0
class GetElementByKey:
    def __init__(self, driver):
        self.read_ini = ReadIni()
        self.driver = driver

    # 根据传入的type 返回元素定位的方法名称
    def get_find_element_fuc(self, find_type):
        if find_type == 'id':
            return self.driver.find_elements_by_id
        elif find_type == 'class':
            return self.driver.find_elements_by_class_name
        elif find_type == 'xpath':
            return self.driver.find_elements_by_xpath

    # 根据元素名称从ini文件中读取对应的value 然后调用driver直接获取返回元素信息
    def get_element(self, element_name, section=None):
        ini_value = self.read_ini.get_ini_value(element_name, section)
        split_ini_value = ini_value.split('>')
        # 配置文件ini 用>分隔调用的type及相应的值
        if len(split_ini_value) >= 2:
            find_type = split_ini_value[0]
            find_key = split_ini_value[1]
            try:
                element_value = self.get_find_element_fuc(find_type)(find_key)
            except:
                element_value = None
            if len(split_ini_value) == 3:
                index = int(split_ini_value[2])
                element_value = element_value[index]
            return element_value
        else:
            return None
    def get_element(self, key):
        read_ini = ReadIni()
        local = read_ini.get_value(key)
        by = local.split('>')[0]
        local_by = local.split('>')[1]
        if local != None:
            if by == 'id':
                return self.driver.find_element_by_id(local_by)
            elif by == 'className':
                return self.driver.find_elements_by_class_name(local_by)
            else:
                return self.driver.find_element_by_android_uiautomator(
                    local_by)

        else:
            return None
Exemple #8
0
    def get_element(self,key):
        read_ini = ReadIni()
        data = read_ini.get_value(key)  #获取键的值
        by = data.split('>')[0] #以>号分割,取第一个
        value = data.split('>')[1]  #以>号分割,取第二个
        try:
            if by == 'id':
                return self.driver.find_element_by_id(value)
            elif by == 'name':
                return self.driver.find_element_by_name(value)
            elif by == 'calssname':
                return self.driver.find_element_by_class_name(value)
            else:
                return self.driver.find_element_by_xpath(value)
        except: #抛异常

            #self.driver.save_screenshot('D:\pycharm\python3\demo\study\web_auto_test\page\%s.png' %value)  #没定位到元素即截图
            return None
class FindElement:
    def __init__(self, driver, filename):
        self.driver = driver
        self.rd = ReadIni(filename)

    def get_element(self, section, key):
        ele_info = self.rd.get_value(section, key)
        by = ele_info.split('>')[0]
        value = ele_info.split('>')[1]
        if by == 'id':
            element = self.driver.find_element_by_id(value)
        elif by == 'xpath':
            element = self.driver.find_element_by_xpath(value)
        elif by == 'class':
            element = self.driver.find_element_by_class_name(value)
        elif by == 'link_text':
            element = self.driver.find_element_by_link_text(value)
        return element
 def __init__(self, driver, filename):
     self.driver = driver
     self.rd = ReadIni(filename)
Exemple #11
0
 def __init__(self, driver):
     self.read_ini = ReadIni()
     self.driver = driver