Appium appiumwebview 切换后识别元素失败

nore · April 19, 2017 · Last by Guo Dalu replied at December 13, 2019 · 1619 hits

脚本如下:
Set contextNames = appiumDriver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName); // 用于返回被测app是NATIVE_APP还是WEBVIEW,如果两者都有就是混合型App
}
appiumDriver.context("WEBVIEW_com.nonobank");
System.out.println(appiumDriver.getContext());
objectRepository.sleep(5000);
logger.info("输入借款金额...");
WebElement element = webObjectRepository.getWebElement("借款金额");
element.sendKeys(borrowMoney);
日志记录:
[debug] [AndroidDriver] Parsed pid: 8273 pkg: com.nonobank!
[debug] [AndroidDriver] from: u0_a360,8273,755,1994200,221004,SyS_epoll_,0000000000,S,com.nonobank
[debug] [AndroidDriver] returning process name: com.nonobank
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.nonobank"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.nonobank"]
[MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com....
[HTTP] <-- GET /wd/hub/session/4b9e9774-f4ea-44d5-b559-02f02420d2b5/contexts 200 212 ms - 109
[HTTP] --> POST /wd/hub/session/4b9e9774-f4ea-44d5-b559-02f02420d2b5/context {"name":"WEBVIEW_com.nonobank"}
[MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.nonobank","4b...
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/user/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","3ad67487","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_8273 mapped to pid 8273
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/user/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","3ad67487","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 8273 pkg: com.nonobank!
[debug] [AndroidDriver] from: u0_a360,8273,755,1969232,211344,0000000000,R,com.nonobank
[debug] [AndroidDriver] returning process name: com.nonobank
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.nonobank"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.nonobank"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.nonobank'
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*--port=9515"
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 9515
Only local connections are allowed.
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"stat...
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"ch...
[JSONWP Proxy] Got response with status 200: {"sessionId":"e8e9465f21109...
[debug] [Chromedriver] Changed state to 'online'
[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/3de788bf-e804-4dab-9da5-c435e4f616dd/context 200 60728 ms - 76
[HTTP] --> GET /wd/hub/session/3de788bf-e804-4dab-9da5-c435e4f616dd/context {}
[MJSONWP] Calling AppiumDriver.getCurrentContext() with args: ["3de788bf-e804-4dab-9da5-c...
[MJSONWP] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.nonobank"
[HTTP] <-- GET /wd/hub/session/3de788bf-e804-4dab-9da5-c435e4f616dd/context 200 2 ms - 94
WEBVIEW_com.nonobank
2017-04-19 14:33:52 [main] INFO com.nonobank.apps.page.webView.Page_webView_emergencyBorrow - 输入借款金额...
问题:
1:System.out.println(appiumDriver.getContext()); 打印WEBVIEW_com.nonobank 说明已经切换成功了
但是Responding to client with driver.setContext() result: null 为什么null啊?

共收到 7 条回复 时间 点赞

[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body

no body

楼主这个文件解决了吗,我也遇到了,无从下手的感觉。

同样遇到这个问题,求解决了的告诉下解决方法,多谢

mark!关注这个问题。
哪位解决了麻烦留个处理方法,Thanks!

nore #6 · February 02, 2018 作者

去配置 Android 手机的 system webview 和 ChromeDriver 和 Chrome 版本 保持一致。 三个统一

我配置成一样的了,怎么还是有这个问题喃😭 困扰我几天了

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up