应用中一般是native app和webview(如H5)混在一起,appium实现在webview中查找元素, 切换context到webview, 然后用xpath查找即可
#查看所有的context
contexts = driver.contexts #一般结果是 [‘NATIVE_APP‘, ‘WEBVIEW_com.xx.xxx‘]
#打印当前的context
print(driver.current_context)
#切换到webview
webview = driver.contexts[1]
driver.switch_to.context(webview)
#切换回native app
driver.switch_to.context(‘NATIVE_APP‘)