zoukankan      html  css  js  c++  java
  • 【Python + Appium】之元素定位总结(待更新)

    一、ID定位

    uiautomatorviewer里面的:resource-id

    driver.find_element(By.ID,"com.csks.businesses:id/tv_number").click()

    二、利用index角标定位

    # 利用index角标定位
    
    # 获取多个输入框
    inputs = driver.find_elements(By.CLASS_NAME,"android.widget.EditText")
    
    # 第一个输入框
    inputs[0].send_keys("18602603xxx")
    # 第二个输入框
    inputs[1].send_keys("123123")

    三、class定位

    # className定位(但是不准)
        driver.find_element(By.CLASS_NAME,"android.widget.TextView").send_keys("18602603XXX")

    四、XPATH定位

    ①text定位

    # Xpath,利用text定位
    driver.find_element(By.XPATH,"//*[@text='DD20200422000001']").click()

    ②组合定位(text与id)

    # Xpath,利用组合定位
    
    driver.find_element(By.XPATH,"//*[@text='请输入密码' and @resource-id='com.csks.businesses:id/edt_password']").send_keys("123123")

    五、坐标定位

    # 点击页面的坐标
    driver.tap([(274, 271), (650, 319)], 500)

    六、寻找元素,并点击元素

    def swipeUp():
            '向上滑动'
            width = driver.get_window_size()['width']
            height = driver.get_window_size()['height']
            driver.swipe(1/2*width,4/5*height,1/2*width,1/5*height)
    
    
    
    # 寻找元素,并点击
    while 1<10:
        try:
            # 模糊定位
            driver.find_element(By.XPATH,"//*[contains(@text,'规格描述:276373')]").click()
            break
        except:
            print("未找到,继续上滑")
            swipeUp()

    七、模糊定位

    # 模糊定位
    
    driver.find_element(By.XPATH,"//*[contains(@text,'规格描述:276373')]").click()

    八、定位Toast

    # 设置参数需要加上如下参数
    
    capabilities.setCapability("automationName", "uiautomator2");
    
    
    
    # 定位toast
    
    toast = driver.find_element(By.XPATH,"//*[contains(@text,'供货数量不能为空')]").text

    附录:

    感谢:含笑半步颠√ 的文章《Appium_Xpath定位详解

    感谢: 的文章《appiumselenium+python 滑动屏幕直至某元素出现

    感谢:清风软件测试  的文章《appium python 点击坐标 tap

    感谢: 的文章《【appium】获取toast内容》

    感谢:的文章《》

    感谢:的文章《》

    感谢:的文章《》

  • 相关阅读:
    PHP面向对象之事务脚本模式
    PHP面向对象之页面控制器
    PHP面向对象之前端控制器模式
    oracle sql分页的写法示例
    PHP面向对象之注册表模式
    PHP面向对象之命令模式
    opencv中Mat类型数据操作与遍历
    Anisotropic gauss filter
    opencv 批量图像读写
    HSV颜色识别demo
  • 原文地址:https://www.cnblogs.com/Owen-ET/p/13452378.html
Copyright © 2011-2022 走看看