appium-操作webview
作者:互联网
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()
标签:webdriver,appium,cons,MobileBy,driver,import,操作,webview 来源: https://www.cnblogs.com/bigcoolcool/p/16101213.html