zoukankan      html  css  js  c++  java
  • appium 元素定位

    查找控件的方式:
      1.通过id查找
      self.driver.find_element_by_id("com.guokr.mentor:id/text_view_topic_title")
      self.driver.find_elements_by_id("")[0]


      2.通过name查找
      self.driver.find_element_by_name("推荐")


      3.通过class_name查找
      self.driver.find_elements_by_class_name("android.widget.TextView")


      4.通过xpath查找
      self.driver.find_element_by_xpath("")


      5.通过uiautomator的方式查找
       self.driver.find_element_by_android_uiautomator()


      6.通过uiautomation的方式查找
      self.driver.find_element_by_ios_uiautomation()

    对控件操作 以下以element代表控件:
      获取手机屏幕分辨率
      width=self.driver.get_window_size()['width']    获取宽
      height=self.driver.get_window_size()['height']   获取高


      1.点击
      element.click()


      2.点击坐标 手机左上角 (0,0)
      mobile: 和tap之间需要有一个空格!  

      self.driver.execute_script("mobile: tap",{"x":0.5*width,"y":0.5*height})

      3.tap点击
      TouchAction(self.driver).tap(element).perform()

      4.滑动flick
      向上滑动为负数,向下滑动为正数 按住一点进行滑动
      向左是负数,向右是整数
      TouchActions(self.driver).flick(-10,-30).perform()


      5.对元素进行滑动 向左是负数,向右是整数 最后一个参数是多长时间
      TouchActions(self.driver).flick_element(element,-100,-100,5).perfor  

      6.swipe滑动 直接滑动

      startX,startY是滑动的起始坐标;endX和endY是滑动的结束坐标;touchCount (默认 为1): 触摸数量,即手指的个数;duration是滑动的持续时间,单位s。
      self.driver.execute_script("mobile: swipe",{'startX':100,'startY':100,'endX':100,'endY':200,'tapCount':1,'duration':2})


      7.长按long_press
      TouchActions(self.driver).long_press(element).perform()
      8.按着某个点拖到另一个点 按住点
      TouchAction(self.driver).press(x=10,y=11).move_to(x=100,y=100).release().perform()

      9.获取值属性 text
      e1=element.text


      10.输入框输入文字
      desired_caps['unicodeKeyboard']='true'
      desired_caps['resetKeyboard']='true'
      首先点击控件 获取到焦点再输入
      element.click()
      element.send_keys(u'宝马')


      11.使用os命令 os命令相当于调用cmd命令
      os.system("adb shell input text 宝马")


      12.安卓keycode
      self.driver.press_keycode(4)

    断言方式 使用unittest 自带有assert的断言方式:
      1.校验值是否一致 assertEqual 预期值 实际值
      self.assertEqual(element.text,"搜你想搜")
      assert cmp("1","2")==0


      2.校验值不一致
      self.assertNotEqual("1","2")


      3.包含关系
      self.assertIn("你好","你好呀")


      4.不包含
      self.assertNotIn("你","他们")

  • 相关阅读:
    数据结构(九)词典
    数据结构(八)高级搜索树
    电脑购买参数配置
    git命令
    Linux安装初始化
    电影TS、TC、BD版和HD版
    eclipse 自动生成json格式的toString()方法
    富文本编辑器-UEditor
    lucene教程--全文检索技术
    FileOperator 文件(夹)操作类
  • 原文地址:https://www.cnblogs.com/pengranxindong/p/9957113.html
Copyright © 2011-2022 走看看