Appium Appium 切换微信 webView 报错,大神帮忙看看,webview 获取是 WEBVIEW_unknown

Cruise · 2019年12月09日 · 最后由 BCHJ 回复于 2020年03月22日 · 2537 次阅读

class Base():
driver = None
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['noReset'] = True
# desired_caps['platformVersion'] = '4.3'
# desired_caps['deviceName'] = '50a4c97e'
desired_caps['platformVersion'] = settings.platformVersion
desired_caps['deviceName'] = settings.deviceName
# desired_caps['platformVersion'] = '5.1'
# desired_caps['deviceName'] = 'A10SBNGTQJ9M'
desired_caps['appPackage'] = settings.appPackage
desired_caps['appActivity'] = settings.appActivity
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
desired_caps['chromeOptions'] = {'androidProcess': 'com.tencent.mm:appbrand0'}

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

def test(self):
print 'test'
# 打开发现页面
element_operate_instances.element_click(common_controls.wechat_find_button)
# 打开小程序页面
element_operate_instances.element_click(common_controls.small_routine_button)
# 打开小程序页面
element_operate_instances.element_click(common_controls.small_routine_me)
# 打开小程序
element_operate_instances.element_click(common_controls.self_wash_button)
# 切换到 webview
BasePage.Base.driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
time.sleep(20)
print(BasePage.Base.driver.page_source)

Appium 后台报错:
[HTTP] --> POST /wd/hub/session/fb1bb72b-b0e8-4f46-ac1f-5286317cbfb4/context
[HTTP] {"name":"WEBVIEW_com.tencent.mm:appbrand0"}
[debug] [W3C (fb1bb72b)] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.tencent.mm:appbrand0","fb1bb72b-b0e8-4f46-ac1f-5286317cbfb4"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Running 'F:\Android\android-sdk\platform-tools\adb.exe -P 5037 -s a41bc84b9805 shell cat /proc/net/unix'
[AndroidDriver] Not checking whether webviews have active pages; use the 'ensureWebviewsHavePages' cap to turn this check on
[debug] [AndroidDriver] WEBVIEW_25091 mapped to pid 25091
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Running 'F:\Android\android-sdk\platform-tools\adb.exe -P 5037 -s a41bc84b9805 shell ps'
[debug] [AndroidDriver] Returning process name: 'unknown'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_unknown"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_unknown"]
[debug] [W3C (fb1bb72b)] Encountered internal error running command: NoSuchContextError: No such context found.
[debug] [W3C (fb1bb72b)] at AndroidUiautomator2Driver.setContext (C:\Users\Cruise\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\context.js:57:11)
[debug] [W3C (fb1bb72b)] at
[HTTP] <-- POST /wd/hub/session/fb1bb72b-b0e8-4f46-ac1f-5286317cbfb4/context 400 602 ms - 328

共收到 4 条回复 时间 点赞

使用 driver.contexts 获取所有的 WEBVIEW
返回结果:
[u'NATIVE_APP', u'WEBVIEW_unknown']

自己顶一下,有没有大神来帮忙看看

我报的也是这个错误,三星 S8+,Appium Server v1.15.1 版本,目前还没找到解决办法。

我这边执行的时候,报这个错,楼主解决了吗?
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"]
[W3C (342f6e01)] Encountered internal error running command: NoSuchContextError: No such context found.
[W3C (342f6e01)] at AndroidUiautomator2Driver.setContext (C:\Users\TF015581\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\context.js:57:11)
[HTTP] <-- POST /wd/hub/session/342f6e01-20ed-4a6b-a991-f24342cae78f/context 400 341 ms - 337
[HTTP]

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册