driver.getContexts 中缺少 WEBVIEW 上下文

Posted

技术标签:

【中文标题】driver.getContexts 中缺少 WEBVIEW 上下文【英文标题】:WEBVIEW context missing from driver.getContexts 【发布时间】:2021-08-05 23:15:37 【问题描述】:

我有一个关于 webdriver.io 的问题,我正在使用 react native 应用程序 .apk, 网络驱动程序/5.23.0 appium_version - 1.17.0

应用之间有一个 webview 来从用户那里获取信息。

问题 我没有将 WEBVIEW 作为可用上下文之一,因此我无法导航到该 webview,也无法导航该 webview 中的元素

当我在真实设备上的浏览器堆栈应用程序中的三星 21 上手动尝试 apk 时,我能够在检查中看到 webview,并能够在检查中查看元素。 但是当我使用 webdriver 代码导航同一个 apk 时,它没有找到 webview 上下文。

任何帮助将不胜感激,如果您想查看,我可以放大并向您展示问题。

code 
contexts = await browser.getContexts();
console.log('************ STEP 2 ************', JSON.stringify(contexts));
await browser.switchContext(contexts[0]);
const continue = await $("//*[@text='Continue']");
await continue.waitForDisplayed(
  timeout: 10000
);
await continue.click()

网络驱动程序日志

2021-05-16T12:46:04.785Z INFO webdriver: [POST] https://hub-cloud.browserstack.com:443/wd/hub/session/b3cf72fbf8fdfb1db61055a650d0fbe627fa19b3/element/00810e16-1198-49b2-8c4c-5b4bcee09864/click
[0-0] 2021-05-16T12:46:09.905Z INFO webdriver: COMMAND getContexts()
[0-0] 2021-05-16T12:46:09.906Z INFO webdriver: [GET] https://hub-cloud.browserstack.com:443/wd/hub/session/b3cf72fbf8fdfb1db61055a650d0fbe627fa19b3/contexts
[0-0] 2021-05-16T12:46:10.014Z INFO webdriver: RESULT [ 'NATIVE_APP' ]
[0-0] ************ STEP 2 ************ ["NATIVE_APP"]
2021-05-16T12:46:10.017Z INFO webdriver: COMMAND switchContext("NATIVE_APP")
2021-05-16T12:46:10.018Z INFO webdriver: [POST] https://hub-cloud.browserstack.com:443/wd/hub/session/b3cf72fbf8fdfb1db61055a650d0fbe627fa19b3/context
2021-05-16T12:46:10.019Z INFO webdriver: DATA  name: 'NATIVE_APP' 

appium 日志

2021-05-16 12:46:08:332 - [HTTP] --> GET /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/contexts
2021-05-16 12:46:08:332 - [HTTP] 
2021-05-16 12:46:08:334 - [debug] [MJSONWP (91dd11eb)] Calling AppiumDriver.getContexts() with args: ["91dd11eb-0bb0-4197-b404-9c1174bca8aa"]
2021-05-16 12:46:08:334 - [debug] [androidDriver] Getting a list of available webviews
2021-05-16 12:46:08:335 - [debug] [ADB] Running '/usr/local/.browserstack/android-sdk/platform-tools/adb -P 5037 -s RFCR204K71P shell cat /proc/net/unix'
2021-05-16 12:46:08:371 - [AndroidDriver] Retrieved potential webviews; will filter out ones with no active pages
2021-05-16 12:46:08:372 - [debug] [AndroidDriver] Found webviews: []
2021-05-16 12:46:08:373 - [debug] [AndroidDriver] Available contexts: ["NATIVE_APP"]
2021-05-16 12:46:08:373 - [debug] [MJSONWP (91dd11eb)] Responding to client with driver.getContexts() result: ["NATIVE_APP"]
2021-05-16 12:46:08:374 - [HTTP] <-- GET /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/contexts 200 42 ms - 86
2021-05-16 12:46:08:374 - [HTTP] 
2021-05-16 12:46:08:515 - [HTTP] --> POST /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/context
2021-05-16 12:46:08:515 - [HTTP] "name":"NATIVE_APP"
2021-05-16 12:46:08:516 - [debug] [MJSONWP (91dd11eb)] Calling AppiumDriver.setContext() with args: ["NATIVE_APP","91dd11eb-0bb0-4197-b404-9c1174bca8aa"]
2021-05-16 12:46:08:516 - [debug] [MJSONWP (91dd11eb)] Responding to client with driver.setContext() result: null
2021-05-16 12:46:08:517 - [HTTP] <-- POST /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/context 200 2 ms - 76
2021-05-16 12:46:08:517 - [HTTP] 
2021-05-16 12:46:08:568 - [HTTP] --> POST /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/element
2021-05-16 12:46:08:568 - [HTTP] "using":"xpath","value":"//*[@text='Continue']"
2021-05-16 12:46:08:570 - [debug] [MJSONWP (91dd11eb)] Calling AppiumDriver.findElement() with args: ["xpath","//*[@text='Continue']","91dd11eb-0bb0-4197-b404-9c1174bca8aa"]
2021-05-16 12:46:08:570 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2021-05-16 12:46:08:570 - [debug] [BaseDriver] Waiting up to 0 ms for condition
2021-05-16 12:46:08:570 - [debug] [WD Proxy] Matched '/element' to command name 'findElement'
2021-05-16 12:46:08:571 - [debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8206/wd/hub/session/9b39fbd2-a3fc-4917-8f43-d7cf35514abc/element] with body: "strategy":"xpath","selector":"//*[@text='Continue']","context":"","multiple":false
2021-05-16 12:46:08:613 - [WD Proxy] Got response with status 404: "sessionId":"9b39fbd2-a3fc-4917-8f43-d7cf35514abc","value":"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:102)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:72)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:51)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCon...
2021-05-16 12:46:08:613 - [debug] [W3C] Matched W3C error code 'no such element' to NoSuchElementError
2021-05-16 12:46:08:614 - [debug] [MJSONWP (91dd11eb)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
2021-05-16 12:46:08:614 - [debug] [MJSONWP (91dd11eb)]     at AndroidUiautomator2Driver.findElOrEls (/nix/store/afabwd5rpmw8z0c4a61ssiq2g0622b6q-appium-1.17.0/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:75:11)
2021-05-16 12:46:08:615 - [HTTP] <-- POST /wd/hub/session/91dd11eb-0bb0-4197-b404-9c1174bca8aa/element 500 46 ms - 164
2021-05-16 12:46:08:615 - [HTTP] 

我可以在网络上找到的最接近的问题如下 https://github.com/appium/appium/issues/6973

【问题讨论】:

【参考方案1】:

作为调试措施,您可以运行测试 appium 版本,如下所述 caps.setCapability("browserstack.appium_version", "1.20.2"); 如果在更新观察相同的行为后写入 support@browserstack.com

【讨论】:

试了以上方法,还是不行,还是一样

以上是关于driver.getContexts 中缺少 WEBVIEW 上下文的主要内容,如果未能解决你的问题,请参考以下文章

Crashlytics:“我们缺少处理崩溃的 dSYM”[关闭]

Spotify Web API - 缺少 401 权限

xp系统报错 windows explorer has encountered a problem and needs to close.We are sorry for the inconvenie

请实现一个函数,把字符串中的每一个空格替换成“%20”,比如输入 “We are Happly。” 则输出“we%20are%20happy。”

请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。

软件工程学期总结