环境信息:
Android 4.4.2 Appium 1.6.3 微信:6.5.3 chrome:55
页面 1:
页面 2:
问题 1:
切换到微信 Webview 后,页面 1 中的搜索框(1)能够输入文字、能够点击搜索按钮,点击搜索按钮后自动跳转到页面 2,在页面 2 的搜索栏(3)输入文字或点击报错。
问题 2:
切换到微信 Webview 后,页面 1 点击医院(3)没有反应。
问题 1,2 在 PC 和 Android 上的 Chrome 浏览器上执行时是正常的,不知道这里切换到微信上的 WEBVIEW 上去执行不了
@seveniruby
Appium 启动命令:
appium -a 127.0.0.1 -p 4723 -bp 4701 --command-timeout 60
切换到 webview 代码:
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'ec3097c9'
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = '.ui.LauncherUI'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps["chromeOptions"] = {'androidProcess': 'com.tencent.mm:tools'}
desired_caps['noReset'] = 'True'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(6)
driver.find_element_by_xpath('//android.widget.TextView[@text=\"通讯录\"]').click()
driver.find_element_by_xpath('//android.widget.TextView[@text=\"公众号\"]').click()
driver.find_element_by_xpath('//android.widget.TextView[@content-desc=\"搜索\"]').click()
driver.find_element_by_id('com.tencent.mm:id/gn').send_keys(u'微医')
driver.find_element_by_xpath('//android.widget.TextView[@text=\"微医集团全流程测试\"]').click()
time.sleep(6)
driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
print driver.current_context
到这里一切正常,打印显示正常切换到了 WEBVIEW_com.tencent.mm:tools
问题 1 代码:
driver.find_element_by_css_selector('#area_hos_list > div:nth-child(3) > a').click()
该命令如果在 PC 浏览器上执行,能够正常执行点击操作,但在微信中执行时,页面没有任务反应,日志也没有发现错误,见 LOG1:
问题 2 代码:
代码:
driver.find_element_by_id('search_val').send_keys('456') 能够执行
driver.execute_script("$('#search_val').val('134')") 能够执行
driver.execute_script("$('#search_val').trigger('touchstart')") 能够执行
driver.find_element_by_id('search_val').send_keys('456') 不能够执行,报错
执行最后一句的日志如下,一直卡在这里不动了。等待一段时间后报错:Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
详细日志见 LOG2
==========================LOG1=============================
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules.2.10.0@appium-chromedriver\chromedriver\win\chromedriver.exe
[Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"8000 "
) do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe
) do (IF NOT %b=="" TASKKILL /F /PID %a))
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules.2.10.0@appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30) on port 8000
Only local connections are allowed.
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1.7601 SP1\"}}}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"ec3097c9"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"0fcc6baf0f2280be4502540a90b87a34","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30)"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":true,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"pageLoadStrategy":"normal","platform":"ANDROID","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"53.0.2785.49","webStorageEnabled":true}}
[debug] [Chromedriver] Changed state to 'online'
[debug] [MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/context 200 3624 ms - 76
[HTTP] --> GET /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/context {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentContext() with args: ["6501ffad-de53-4d9c-8bc1-eeedb75cf15a"]
[debug] [MJSONWP] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.tencent.mm:tools"
[HTTP] <-- GET /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/context 200 5 ms - 102
[HTTP] --> POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element {"using":"css selector","sessionId":"6501ffad-de53-4d9c-8bc1-eeedb75cf15a","value":"#area_hos_list > div:nth-child(3) > a"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element] to [POST http://127.0.0.1:8000/wd/hub/session/0fcc6baf0f2280be4502540a90b87a34/element] with body: {"using":"css selector","sessionId":"6501ffad-de53-4d9c-8bc1-eeedb75cf15a","value":"#area_hos_list > div:nth-child(3) > a"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"0fcc6baf0f2280be4502540a90b87a34","status":0,"value":{"ELEMENT":"0.30164056734463274-1"}}
[JSONWP Proxy] Replacing sessionId 0fcc6baf0f2280be4502540a90b87a34 with 6501ffad-de53-4d9c-8bc1-eeedb75cf15a
[HTTP] <-- POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element 200 352 ms - 107
[HTTP] --> POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element/0.30164056734463274-1/click {"sessionId":"6501ffad-de53-4d9c-8bc1-eeedb75cf15a","id":"0.30164056734463274-1"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element/0.30164056734463274-1/click] to [POST http://127.0.0.1:8000/wd/hub/session/0fcc6baf0f2280be4502540a90b87a34/element/0.30164056734463274-1/click] with body: {"sessionId":"6501ffad-de53-4d9c-8bc1-eeedb75cf15a","id":"0.30164056734463274-1"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"0fcc6baf0f2280be4502540a90b87a34","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId 0fcc6baf0f2280be4502540a90b87a34 with 6501ffad-de53-4d9c-8bc1-eeedb75cf15a
[HTTP] <-- POST /wd/hub/session/6501ffad-de53-4d9c-8bc1-eeedb75cf15a/element/0.30164056734463274-1/click 200 667 ms - 76
[BaseDriver] Shutting down because we waited 60 seconds for a command
[debug] [AndroidDriver] Shutting down Android driver
==========================LOG2=============================
[debug] [MJSONWP] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.tencent.mm:tools"
[HTTP] <-- GET /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/context 200 2 ms - 102
[HTTP] --> POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element {"using":"id","sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","value":"search_val"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element] to [POST http://127.0.0.1:8000/wd/hub/session/052bbafb8738cfd4505394d1a9633daf/element] with body: {"using":"id","sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","value":"search_val"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"052bbafb8738cfd4505394d1a9633daf","status":0,"value":{"ELEMENT":"0.3256719186734802-1"}}
[JSONWP Proxy] Replacing sessionId 052bbafb8738cfd4505394d1a9633daf with ea968a23-10cc-4187-bba1-91979a76a661
[HTTP] <-- POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element 200 296 ms - 106
[HTTP] --> POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element/0.3256719186734802-1/value {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","id":"0.3256719186734802-1","value":["4","5","6"]}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element/0.3256719186734802-1/value] to [POST http://127.0.0.1:8000/wd/hub/session/052bbafb8738cfd4505394d1a9633daf/element/0.3256719186734802-1/value] with body: {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","id":"0.3256719186734802-1","value":["4","5","6"]}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"052bbafb8738cfd4505394d1a9633daf","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId 052bbafb8738cfd4505394d1a9633daf with ea968a23-10cc-4187-bba1-91979a76a661
[HTTP] <-- POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element/0.3256719186734802-1/value 200 524 ms - 76
[HTTP] --> POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","args":[],"script":"$('#search_val').val('134')"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute] to [POST http://127.0.0.1:8000/wd/hub/session/052bbafb8738cfd4505394d1a9633daf/execute] with body: {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","args":[],"script":"$('#search_val').val('134')"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"052bbafb8738cfd4505394d1a9633daf","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId 052bbafb8738cfd4505394d1a9633daf with ea968a23-10cc-4187-bba1-91979a76a661
[HTTP] <-- POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute 200 96 ms - 76
[HTTP] --> POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","args":[],"script":"$('#search_val').trigger('touchstart')"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute] to [POST http://127.0.0.1:8000/wd/hub/session/052bbafb8738cfd4505394d1a9633daf/execute] with body: {"sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","args":[],"script":"$('#search_val').trigger('touchstart')"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"052bbafb8738cfd4505394d1a9633daf","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId 052bbafb8738cfd4505394d1a9633daf with ea968a23-10cc-4187-bba1-91979a76a661
[HTTP] <-- POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/execute 200 115 ms - 76
[HTTP] --> POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element {"using":"id","sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","value":"search_val"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element] to [POST http://127.0.0.1:8000/wd/hub/session/052bbafb8738cfd4505394d1a9633daf/element] with body: {"using":"id","sessionId":"ea968a23-10cc-4187-bba1-91979a76a661","value":"search_val"}
[MJSONWP] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
at doJwpProxy$ (../../../lib/mjsonwp/mjsonwp.js:343:13)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules.5.8.24@babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as throw
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules.5.8.24@babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/ea968a23-10cc-4187-bba1-91979a76a661/element 500 240047 ms - 281
[Chromedriver] [STDERR] [307.523][SEVERE]: Timed out receiving message from renderer: 299.999