import time
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# adb devices
# adb connect 127.0.0.1:62001
# 1 手机的配置信息
info = {
# "automationName": "UIAutomator2",
#1 测试的平台
"platformName": "Android",
# 2 版本号 关于 -- 版本号
"platformVersion": "7.1.2",
# 3 设备名
"deviceName": "127.0.0.1:62001",
"appPackage": "com.vy.visvacn",
# 界面名称
"appActivity": "com.vy.visvacn.module.splash.SplashActivity",
"noReset": True
}
# 启动程序
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", info)
loc = (MobileBy.ID, 'com.vy.visvacn:id/tv_agree')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located(loc))
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/tv_agree').click()
loc_login = (MobileBy.ACCESSIBILITY_ID, '验证码登录')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located(loc_login))
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/menu_item_view').click()
loc_pwd = (MobileBy.ACCESSIBILITY_ID, '密码登录')
WebDriverWait(driver, 20).until((EC.visibility_of_element_located(loc_pwd)))
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/input_phone_view').send_keys('15989898989')
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/input_pwd_view').send_keys('123456789')
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/action_view').click()
try:
loc = (MobileBy.XPATH, '//*[contains(@text,"{}")]'.format("请勾选同意相关协议"))
# WebDriverWait(driver, 10, 0.001).until(EC.presence_of_element_located(loc))
print(driver.find_element(MobileBy.XPATH, '//*[contains(@text,"{}")]'.format("请勾选同意相关协议")).text)
except Exception as e:
print(e)
time.sleep(5)
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/action_agree_view').click()
driver.find_element(MobileBy.ID, 'com.vy.visvacn:id/action_view').click()
try:
loc = (MobileBy.XPATH, '//*[contains(@text,"{}")]'.format("手机号或密码错误"))
# WebDriverWait(driver, 10, 0.001).until(EC.presence_of_element_located(loc))
print(driver.find_element(MobileBy.XPATH, '//*[contains(@text,"{}")]'.format("手机号或密码错误")).text)
except Exception as e:
print(e)
driver.quit()