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)
# 等待webview元素出现
webdriverwait(driver, 20). \
until(EC.visibility_of_element_located((MobileBy.ANDROID_UIAUTOMATOR, 'New UiSelector().text("")')))
time.sleep(1)
cons = driver.contexts # 获取上下文
print(cons)
driver.switch_to.context(cons[-1]) # 切换上下文
webdriverwait(driver, 20).until(EC.visibility_of_element_located(MobileBy.XPATH, ""))
driver.find_element(MobileBy.XPATH, "").click()