APPIUM 小程序webview问题

小程序许多界面都是hybrid,有些webview页面用uiautomator viewer查看不到元素,这里就要 获取webview 的pagesource了

1.环境:

  需要确定appium_chromedriver的版本和微信的webview版本对应:

获取微信的webview版本信息,打开x5调试debugx5.qq.com 在信息页面下打开对应的inspector调试 然后进入谷歌浏览器chrome://inspect/#devices在

对应的设备下查看 appium_chromedriver版本自行百度

2.app启动参数:

在caps中指定对应的driver:

1.caps['chromedriverExecutableDir']=r'C:\Users\Administrator\Desktop\appium_chromedriver'

2.caps['chromedriverExecutable']=r'C:\Users\Administrator\Desktop\appium_chromedriver\chromedriver.exe'

加上对应Androidprocess

caps['chromeOptions']={'androidProcess':xxxx',

'args': ['--no-sandbox']

}

其中获取androidProcess的方法为: 先进入对应界面

获取进程pid

adb shell dumpsys activity top | findstr ACTIVITY

获取name

adb shell ps + pid

3.代码:

# print("======")
# contexts=driver.contexts
# print(contexts)
#
driver.switch_to.context("WEBVIEW_com.tencent.wework")
print("switch success")
# all_handles = driver.window_handles
# print (len(all_handles))
# print(all_handles)
# print (driver.page_source)

4.退出webview回到native

 driver.switch_to.context("NATIVE_APP")