App自动化之native和webview的切换
1、切换到webview
# 获取contexts
contexts = driver.contexts
print(contexts)
# 通过获取的contexts索引进行切换到webview
driver.switch_to.context(contexts[1])
# 通过名称进行切换到webview,名称格式为WEBVIEW_appPackage包名
# driver.switch_to.context('WEBVIEW_AppPackage包名')
切换到webview后,就可以对元素进行定位,定位方法跟web元素定位一样。
定位webview,推荐一个 uc-devtools调试工具,
2、切回到native
# 通过获取的contexts索引切回native
driver.switch_to.context(contexts[0])
# 通过名称进行切回native,名称为NATIVE_APP
# driver.switch_to.context("NATIVE_APP")