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