Appium自动化之H5页元素定位

  • 示例:

  针对手机浏览器检索结果页的某内容进行定位

  • 方案:

    一:css选择器(find_element_by_css_selector)  

  driver.find_element_by_css_selector('a.btn.btn-bg2')

    二:Appium万能id(find_element_by_id)   

  driver.find_element_by_id('diaphone')

  id就是用chrome进行元素定位,找到前端源码中对应控件的id指定就好了。 

  • H5中做点击、跳转、控制键盘、输入等操作

    方案一:用Appium封装的press_keycode:

  # 点击删除键,keycode 4 代表KEYCODE_BACK
  driver.press_keycode(4)

    keycode有一定局限性,不能输入中文,且需要找到对应的key映射,不方便

    方案二:定位到input后直接用sendkeys去输入

      如上文的id是diaphone的控件就是一个input控件,这时候就可以直接如下操作:

  inputbox = driver.find_element_by_id('diaphone')
  inputbox.send_keys('13000000000')

    参考搜狗测试公号  https://mp.weixin.qq.com/s/wQHFUQUuh_vJ-4AyhFpobQ

原文地址:https://www.cnblogs.com/mncasey/p/13215231.html