- ?点击 android-sdk -> tools ->?uiautomatorviewer.bat,打开工具。
from appium import webdriver
import time
desired_caps = dict()
# 手机参数
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
# 应用参数
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
# 获取driver
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
driver.find_element_by_id("com.android.settings:id/search").click()
time.sleep(3) # 这里必须使用睡眠时间,因为页面是需要跳转时间的,如果页面还没有跳转过去就获取搜索框的话,就无法获取到元素。
driver.find_element_by_class_name("android.widget.EditText").send_keys("猪猪杨")
driver.find_element_by_xpath("//*[@content-desc='收起']").click()
time.sleep(3)
# 退出driver
driver.quit()
?
?
?
?
?
|