求解答:appium 打开微信,然后微信中打开 H5,我切换 context 到 webview 之后,可以通过 webdriver 的方法获取元素。但是获取元素点击之后跳转到新的 H5 页面,在新的 H5 页面做任何操作都没有反应,appium 服务器没有收到手机返回的请求。求问怎么解决, 已经折腾了两天了,实在看不出原因。
https://testerhome.com/topics/6954 参考下这篇文章。
早参考过这篇文章了的,我的问题不太一样。我是切换成功了 webview 的,说的是我打开一个 H5,然后点击了 H5 里面的链接在当前页加载了另一个 H5 页面,但是这个 H5 页面没法用 appium 的所有方法操作。
确认下你加载另一个 h5 的方式是直接跳转,还是新开了个窗口?或者是不是增加了一个新的 context ?
如果有多个窗口或者多个 context ,需要切换到当前显示的那个再控制才行。
#4 楼 @Lihuazhang 我打印过 context 和 window handler 都没增加
—— 来自 TesterHome 官方 安卓客户端
#3 楼 @chenhengjie123 不是新窗口,链接是在当前页打开的,而且新页面加载完之后,连打印 context 之类的命令都没有 response 了
—— 来自 TesterHome 官方 安卓客户端
把你完整的日志发上来,并且说明下哪部分是你切换 webview 后做的 切换 context 到 webview 后获取元素点击
,哪部分是 点击后在新页面操作
我看你的日志里切换了 webview 后貌似就一直没响应了直到 60 秒自动断开连接。
@limit 楼主的问题是? 能定位操作第一个 webview 界面 然后在第一个 webview 界面实行 click 进入第二个 webview 界面 无法操作 session 一直处于缓冲状态 1 分钟后报错? get source 看看当前页 有没有内容
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 install "D:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.tencent.mm -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: wake
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data\/local\/tmp"}
info: [debug] dataDir set to: /data/local/tmp
info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
info: [debug] Getting device API level
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 21
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.tencent.mm/.ui.LauncherUI"
info: [debug] Waiting for pkg "com.tencent.mm" and activity ".ui.LauncherUI" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "dumpsys window windows"
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "getprop ro.build.version.release"
info: [debug] Device is at release version 5.0
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId 5821155f-c340-4d3d-ad20-9f5ee64e3b86
info: <-- POST /wd/hub/session 303 8293.583 ms - 74
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86 {}
info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.0","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"unicodeKeyboard":true,"deviceName":"bbc561b8","chromeOptions":{"androidProcess":"com.tencent.mm:tools"},"resetKeyboard":true,"appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"},"unicodeKeyboard":true,"deviceName":"bbc561b8","chromeOptions":{"androidProcess":"com.tencent.mm:tools"},"resetKeyboard":true,"appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86 200 1.124 ms - 751 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.0","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"unicodeKeyboard":true,"deviceName":"bbc561b8","chromeOptions":{"androidProcess":"com.tencent.mm:tools"},"resetKeyboard":true,"appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"},"unicodeKeyboard":true,"deviceName":"bbc561b8","chromeOptions":{"androidProcess":"com.tencent.mm:tools"},"resetKeyboard":true,"appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/timeouts/implicit_wait {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","ms":10000}
info: [debug] Set Android implicit wait to 10000ms
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/timeouts/implicit_wait 200 0.794 ms - 76 {"status":0,"value":null,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "cat /proc/net/unix"
info: [debug] Available contexts:
info: [debug] []
info: [debug] Available contexts: NATIVE_APP
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts 200 46.171 ms - 86 {"status":0,"value":["NATIVE_APP"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context {}
info: [debug] Responding to client with success: {"status":0,"value":"NATIVE_APP","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context 200 0.918 ms - 84 {"status":0,"value":"NATIVE_APP","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/elements {"using":"id","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"com.tencent.mm:id/bpx"}
info: [debug] Waiting up to 10000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.tencent.mm:id/bpx","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.tencent.mm:id/bpx","context":"","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/bpx using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/bpx using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":[]}
info: [debug] Waited for 2139ms so far
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.tencent.mm:id/bpx","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.tencent.mm:id/bpx","context":"","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/bpx using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/bpx using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (2)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=2, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (3)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=3, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (4)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=4, RESOURCE_ID=com.tencent.mm:id/bpx]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"}]}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"}],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/elements 200 9885.798 ms - 137 {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"},{"ELEMENT":"3"},{"ELEMENT":"4"}],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/3/click {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","id":"3"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"3"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/3/click 200 2013.265 ms - 76 {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element {"using":"id","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"com.tencent.mm:id/i3"}
info: [debug] Waiting up to 10000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.tencent.mm:id/i3","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.tencent.mm:id/i3","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/i3 using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/i3]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"5"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"5"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element 200 36.178 ms - 87 {"status":0,"value":{"ELEMENT":"5"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/5/click {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","id":"5"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"5"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"5"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/5/click 200 1597.871 ms - 76 {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element {"using":"id","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"com.tencent.mm:id/ll"}
info: [debug] Waiting up to 10000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.tencent.mm:id/ll","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.tencent.mm:id/ll","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.tencent.mm:id/ll using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.tencent.mm:id/ll]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"6"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"6"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element 200 61.881 ms - 87 {"status":0,"value":{"ELEMENT":"6"},"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/6/click {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","id":"6"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"6"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"6"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/6/click 200 2062.956 ms - 76 {"status":0,"value":true,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "cat /proc/net/unix"
info: [debug] WEBVIEW_14053 mapped to pid 14053
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "ps"
info: [debug] Parsed pid: 14053 pkg: com.tencent.mm:tools
info: [debug] from: u0_a207,14053,317,2370452,234212,ffffffff,00000000,S,com.tencent.mm:tools
info: [debug] returning process name: com.tencent.mm:tools
info: [debug] Available contexts: NATIVE_APP
info: [debug] ["WEBVIEW_com.tencent.mm:tools"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts 200 252.586 ms - 117 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","name":"WEBVIEW_com.tencent.mm:tools"}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "cat /proc/net/unix"
info: [debug] WEBVIEW_14053 mapped to pid 14053
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "ps"
info: [debug] Parsed pid: 14053 pkg: com.tencent.mm:tools
info: [debug] from: u0_a207,14053,317,2370452,234212,ffffffff,00000000,R,com.tencent.mm:tools
info: [debug] returning process name: com.tencent.mm:tools
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
info: [debug] ["WEBVIEW_com.tencent.mm:tools"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
info: [debug] Connecting to chrome-backed webview
info: Chromedriver: Changed state to 'starting'
info: Chromedriver: Set chromedriver binary as: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 "
) do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe
) do (IF NOT %b=="" TASKKILL /F /PID %a))
info: Chromedriver: No old chromedrivers seemed to exist
info: Chromedriver: Spawning chromedriver with: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
info: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 9515
Only local connections are allowed.
info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1 SP1\"}}}"
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"bbc561b8"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"a3198efbfc3ebd3eb5753e3817aec154","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSel...
info: Chromedriver: Changed state to 'online'
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context 200 1258.877 ms - 76 {"status":0,"value":null,"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context {}
info: [debug] Responding to client with success: {"status":0,"value":"WEBVIEW_com.tencent.mm:tools","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context 200 1.377 ms - 102 {"status":0,"value":"WEBVIEW_com.tencent.mm:tools","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element {"using":"xpath","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"//[@id=\"main\"]/a[4]"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element] to [POST http://127.0.0.1:9515/wd/hub/session/a3198efbfc3ebd3eb5753e3817aec154/element] with body: {"using":"xpath","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"//[@id=\"main\"]/a[4]"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"a3198efbfc3ebd3eb5753e3817aec154","status":0,"value":{"ELEMENT":"0.5707436547366542-1"}}
info: JSONWP Proxy: Replacing sessionId a3198efbfc3ebd3eb5753e3817aec154 with 5821155f-c340-4d3d-ad20-9f5ee64e3b86
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element 200 156.442 ms - 106
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/0.5707436547366542-1/click {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","id":"0.5707436547366542-1"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/0.5707436547366542-1/click] to [POST http://127.0.0.1:9515/wd/hub/session/a3198efbfc3ebd3eb5753e3817aec154/element/0.5707436547366542-1/click] with body: {"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","id":"0.5707436547366542-1"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"a3198efbfc3ebd3eb5753e3817aec154","status":0,"value":null}
info: JSONWP Proxy: Replacing sessionId a3198efbfc3ebd3eb5753e3817aec154 with 5821155f-c340-4d3d-ad20-9f5ee64e3b86
info: <-- POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element/0.5707436547366542-1/click 200 192.190 ms - 76
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "cat /proc/net/unix"
info: [debug] WEBVIEW_14053 mapped to pid 14053
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "ps"
info: [debug] Parsed pid: 14053 pkg: com.tencent.mm:tools
info: [debug] from: u0_a207,14053,317,2446404,308680,ffffffff,00000000,R,com.tencent.mm:tools
info: [debug] returning process name: com.tencent.mm:tools
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
info: [debug] ["WEBVIEW_com.tencent.mm:tools"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/contexts 200 205.263 ms - 117 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"],"sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context {}
info: [debug] Responding to client with success: {"status":0,"value":"WEBVIEW_com.tencent.mm:tools","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: <-- GET /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/context 200 0.602 ms - 102 {"status":0,"value":"WEBVIEW_com.tencent.mm:tools","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86"}
info: --> POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element {"using":"name","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"player-id"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/5821155f-c340-4d3d-ad20-9f5ee64e3b86/element] to [POST http://127.0.0.1:9515/wd/hub/session/a3198efbfc3ebd3eb5753e3817aec154/element] with body: {"using":"name","sessionId":"5821155f-c340-4d3d-ad20-9f5ee64e3b86","value":"player-id"}
info: [debug] Didn't get a new command in 60 secs, shutting down...
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "input keyevent 3"
info: [debug] Resetting IME to 'io.appium.android.ime/.UnicodeIME'
info: [debug] executing cmd: E:\android-sdk-windows\platform-tools\adb.exe -s bbc561b8 shell "ime set io.appium.android.ime/.UnicodeIME"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Stopping chromedriver for context WEBVIEW_com.tencent.mm:tools
info: Chromedriver: Changed state to 'stopping'
info: JSONWP Proxy: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/a3198efbfc3ebd3eb5753e3817aec154] with no body
差不多就是这样子,我是 click 之后,立马 print contexts 和 current_context 都 ok,就是页面加载完之后在页面操作怎么都不行。。。
还试过其他人建议说的:先切换回 nactive_app 然后再切换回 webview 还是不行
—— 来自 TesterHome 官方 安卓客户端
是 chromedriver 的 bug
参考 “https://testerhome.com/topics/7851”
@limit 每次页面跳转加上等待时间,你用了 chrome2.26 后,问题是找不到元素,还是 chromedriver session 未响应?
一般日志卡在下面这一行就是 chromedriver session 未响应然后超时
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"fab54491"}}}
如果不是,给每步加上等待时间(与网络和设备性能关系很大),试试
我是 windows 环境,直接执行命令杀进程的(java 语言, Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");),H5 页面不会关闭的。
wmi1 = win32com.client.GetObject('winmgmts:')
c = wmi.WMI()
for p in wmi1.InstancesOf('win32_process'):
if p.Name == 'chromedriver.exe':
for process in c.win32_Process(ProcessId=p.Properties_('ProcessId')):
process.Terminate()
代码有点乱,windows 下亲测这样可以成功
@limit 给楼主 点赞
@limit 楼主我复制你的代码
是不是需要导入什么包
你的 c = wmi.WMI() 中 vmi 是不是少了个 1 ->vmi1
@limit 非常感谢
请问一下,appium 里面怎么获取 window handler,我是 from appium import webdriver,可以获取 contents,但是获取 window handler 的时候会报错,WebDriverException: Message: Method has not yet been implemented
大神,微信怎么切换 H5。代码能分享一下?java 的,求助 188368459@qq.com
先顶一个
有没更好的解决方案,这样脚本写起来太麻烦了.git 上说 1.5 后加了 recreateChromeDriverSessions 这个参数可以解决.但是我用了没效果.
楼主,真机上跑自动化,python 如何实现杀掉进程呀
@limit 问题处理好了不? 帮看看是什么问题, 谢谢。
开发环境:
windows10 + appium-desktop1.5.0 + 小米 5plus(android7.0) + chromedriver=2.26
源码:
public static void main(String[] args) throws InterruptedException, MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver driver = null;
//设置 apk 的路径
File clasPathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(clasPathRoot, "apps");
File app = new File(appDir, "weixin_1300.apk");// app 安装包
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformVersion", "7.0");
capabilities.setCapability("deviceName", "3bf6f87e");//真机
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.tencent.mm");
capabilities.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");
capabilities.setCapability("noReset", true);// 不重装 app
capabilities.setCapability("noSign", true);// 不进行重签名
capabilities.setCapability("sessionOverride", true);
// 权限
capabilities.setCapability("autoGrantPermissions", true);
// 设置 apk 路径
capabilities.setCapability("app", app.getAbsolutePath());
//加入微信 webwiew 调试能力. ===== 加下面这几句就出错了。
ChromeOptions options2 = new ChromeOptions();
options2.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
capabilities.setCapability(ChromeOptions.CAPABILITY, options2);
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
报错如下:
Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. (Original error: unknown error: Failed to clear data for com.android.chrome on device 3bf6f87e: Error: java.lang.SecurityException: PID 19864 does not have permission android.permission.CLEAR_APP_USER_DATA to clear data of package com.android.chrome
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.15063 x86_64)) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 47.67 seconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
System info: host: 'JIANGNENGTING', ip: '192.168.18.254', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:132)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:79)
at com.jnt.csair.weixin.H5Weixin.main(H5Weixin.java:59)
https://github.com/richshaw2015/wxapp-appium
推荐这个技术方案,目前最稳定好用的,经过工程实践检验的