iOS appium元素定位,封装时候使用MobileBy和By结合

iOS:

from selenium.webdriver.common.by import By
class MobileBy(By):
    IOS_PREDICATE = '-ios predicate string'
    IOS_UIAUTOMATION = '-ios uiautomation'
    IOS_CLASS_CHAIN = '-ios class chain'
    ANDROID_UIAUTOMATOR = '-android uiautomator'
    ANDROID_VIEWTAG = '-android viewtag'
    ANDROID_DATA_MATCHER = '-android datamatcher'
    ACCESSIBILITY_ID = 'accessibility id'
    IMAGE = '-image'
    CUSTOM = '-custom'

android:

class By(object):
    """
    Set of supported locator strategies.
    """

    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"

综合封装:

def find_element(self, *loc):
    try:
        # 元素可见时,返回查找到的元素;以下入参为元组的元素,需要加*
        WebDriverWait(self.driver, 30).until(lambda driver: driver.find_element(*loc).is_displayed())
        return self.driver.find_element(*loc)

    except selenium.common.exceptions.NoSuchElementException:
        # logging.warning('Can not find element: %s' % loc[1])
        self.log.myloggger('Can not find element: %s' % loc[1], flag=2)
        raise
    except selenium.common.exceptions.TimeoutException:
        self.log.myloggger('Can not find element: %s' % loc[1], flag=2)
        raise

def find_elements(self, *loc):
    try:
        WebDriverWait(self.driver, 30).until(lambda driver: driver.find_elements(*loc))
        return self.driver.find_elements(*loc)

    except selenium.common.exceptions.NoSuchElementException:
        # logging.warning('Can not find element: %s' % loc[1])
        self.log.myloggger('Can not find element: %s' % loc[1], flag=2)
        self.get_screenshot()
        raise

你可能感兴趣的:(iOS appium元素定位,封装时候使用MobileBy和By结合)