习题1:在首页搜索框中输入“小米手机”,点击搜索按钮 点击搜索到的第一个商品,进入商品详情页 点击“加入购物车”,购买数量为2件,并确定 暂停5秒,关闭驱动 要求:设置隐式等待10秒
import time
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
server = "http://127.0.0.1:4723/wd/hub"
# tpshop配置参数
desired_caps = {
"platformName": "Android",# 系统型号
"deviceName": "xxx",#设备号
"autoGrantPermissions": True,#是否自动授权
"appPackage": "com.tpshop.malls",#APP的包名
"appActivity": ".SPMainActivity"#app打开的第一个界面
}
driver = webdriver.Remote(server, desired_caps)
# 添加隐式等待
driver.implicitly_wait(10)
# 在首页搜索框中输入“小米手机”,点击搜索按钮
driver.find_element(MobileBy.CLASS_NAME,'android.widget.EditText').click()
driver.find_element(MobileBy.CLASS_NAME,'android.widget.EditText').send_keys('小米手机')
driver.find_element(MobileBy.CLASS_NAME,'android.widget.TextView').click()
# 点击搜索到的第一个商品,进入商品详情页
#定位综合元素点击元素的相对于坐标偏移量 x=100, y=160
return_el = driver.find_element(MobileBy.XPATH, "//*[@text='综合']")
TouchAction(driver).tap(return_el, x=100, y=160).perform()
# 点击“加入购物车”,
driver.find_element(MobileBy.ID,'com.tpshop.malls:id/add_cart_tv').click()
# 购买数量为2件,clear清除1;send_keys输入2
driver.find_element(MobileBy.CLASS_NAME,'android.widget.EditText').clear()
driver.f