Appium學習筆記13-點擊、輸入(中文)、清空

#點擊
element.click()
#輸入 
element.send_keys()
#清空
element.clear()
#p.s.默認情況下輸入中文不會報錯,但是結果沒有輸入。若要輸入中文需在上文中增加下面兩行代碼
desire_caps['unicodeKeyboard'] = True
desire_caps['resetKeyboard'] = True

代碼:

#導入庫
from appium import webdriver
import time

desired_caps = dict()#創建字典
desired_caps['platformName'] = 'Android'#添加字典字段:手機平臺(Android、iOS)
desired_caps['platformVersion'] = '5.1'#添加字典字段:系統版本號(可從手機的設置裏面查看)
desired_caps['deviceName'] = 'myphone'#添加字典字段:設備名稱(隨便寫即可)
desired_caps['appPackage'] = 'com.android.settings'#添加字典字段:要打開的app包名
desired_caps['appActivity'] = 'com.android.settings.Settings'#添加字典字段:APP的界面名
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)#調用方法,其中'http://localhost:4723/wd/hub'即爲appium服務器地址
driver.find_element_by_id("android:id/button1").click()#根據id定位元素,彈出應用的授權框,點擊“確認”

driver.find_element_by_xpath("//*[@content-desc='搜索']").click()#根據xpath定位搜索的放大鏡圖標,並點擊搜索
driver.find_element_by_class_name("com.meizu.common.widget.SearchEditText").send_keys("hello")#根據class定位元素,並鍵入“hello”
time.sleep(3)#等待3秒
driver.find_element_by_class_name("com.meizu.common.widget.SearchEditText").clear()#根據class定位輸入框,清空輸入框
time.sleep(3)#等待3秒

driver.find_element_by_class_name("com.meizu.common.widget.SearchEditText").send_keys("你好")#輸入中文的“你好”
time.sleep(3)#等待3秒
driver.quit()#退出此次驅動連接
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章