一、先做好与各个设备的连接: appium与模拟器
二、appium中写好参数(要测试的apk),启动会话
三、通过class name定位,关闭广告
先获取class_name的值
因为他不是appium中推荐的定位元素,说不明有可能不是唯一的,那么就需要来查一查咯
先复制class name的值
将之前的classname粘贴进去,点击search搜索
通过我的鼠标左击来查看关闭广告的classname属于第2个,那么下标就是1
四、代码实现
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import time
dic = {
"platformVersion":"5.1.1",
"platformName":"Android",
"deviceName":"127.0.0.1:62001",
"appPackage":"com.jhss.youguu",
"appActivity":".SplashActivity"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub",dic)
driver.implicitly_wait(20)
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).press(x = 837,y=760).move_to(x=56,y=868).release().perform()
time.sleep(5)
TouchAction(driver).tap(x=462,y=1457).perform()
# 点击关闭广告,通过classname
time.sleep(3) # 等待广告弹出
driver.find_elements_by_class_name('android.widget.ImageView')[1].click()
需要注意的是,当出现一样的元素值时,我们可以通过find_elements来获取一组元素,之后再根据下标进行切换