1.打开安卓模拟器、调整到对应界面

 

2.打开定位元素工具

 

 3.代码

from time import sleep
from appium import webdriver

# 连接移动设备必须的参数
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = {}

# 操作系统
desired_caps["platformName"] = "Android"
# android系统的版本
desired_caps["platformVersion"] = "7.1.1"

# 当前要测试的设备名称
desired_caps["deviceName"] = "127.0.0.1:62001"
# 要启动的APP的包名
desired_caps["appPackage"] = "com.android.settings"   #设置的包名
# 要启动APP哪个页面
desired_caps["appActivity"] = "com.android.settings.Settings"    #设置界面


driver = webdriver.Remote(command_executor="http://127.0.0.1:4723/wd/hub", desired_capabilities=desired_caps)

#获取元素,点击搜索
el = driver.find_element(by= AppiumBy.ID,value = "com.android.settings:id/search")
el.click()

sleep(2)#需要有个等待时间,否则页面还没显示,就获取id,获取不到

#获取元素,输入文本
el = driver.find_element(by= AppiumBy.ID,value = "android:id/search_src_text")
el.send_keys("蓝牙")

sleep(5)
driver.quit()

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐