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()#退出此次驱动连接
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值