appium自动化测试(3)-控件定位&中文输入



◆ 控件定位就是精确的描述控件特征并告诉机器的过程。控件的特征就是控件的属性,可以通过上一讲中的uiautomatorviewer去获取。以下是方法:
1、通过 resourceID获取  driver . find_element_by_id ( "com.android.contacts:id/menu_add_contact" ). click ()
2、通过name :findElementByName( "name")
3、findElementByClassName(”classname“)
4、findElementByAccessibilityId() 在安卓上等同于contentDescription
 
 
◆ 中文输入法:乱码&输入中文报错的解决方法
  1. #coding=utf-8
  2. import time
  3. from appium import webdriver
  4. desired_caps ={}
  5. desired_caps['platformName']='Android'
  6. desired_caps['platformVersion']='4.4.4'
  7. desired_caps['deviceName']='Android Emulator'
  8. desired_caps['appPackage']='com.XX.activity'
  9. desired_caps['appActivity']='.XXSearchActivity'
  10. desired_caps['unicodeKeyboard']=True
  11. desired_caps['resetKeyboard']=True
  12. driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  13. driver.find_elements_by_name("搜索话题")
  14. driver.find_element_by_class_name("android.widget.EditText").send_keys(u"可爱")
  15. # driver.find_element_by_id('et_searchactivity_search').send_keys(u"可爱")
  16. driver.find_element_by_name("搜索").click()
  17. time.sleep(5)//在页面暂停5秒
  18. driver.quit()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 





 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM