Appium android-webview 在 webview 第二次切换的时候,识别不到元素

低调 · 2019年01月07日 · 最后由 清风的故事 回复于 2019年01月08日 · 2225 次阅读

这几天一直解决不了这个问题,求助下社区大神,谢谢!
我的环境:
jdk 1.8
appium : 1.8.1

描述: 进入 APP 后,从 native_app 跳转到 webview 页面 A,点击购买按钮后跳转到另外一个 webview 页面 B(这里我打印了一下,发现和前一个 webview 页面 A 的 url 相同,webview 名称相同,不过窗口 windowhandle 不相同,代码做了切换),然后点击元素的时候报错

我的代码:

    Thread.sleep(2000);
    //进入webview页面
    AndroidOperate.switchToWebview();
    tanxinCtyunHostPage.buyButton.click();//点击购买按钮
    Thread.sleep(2000);
    AndroidOperate.switchToWindowTitle("产品选购"); //跳转到第二个webview页面
    Thread.sleep(3000);
    productChoosePage.ziyuanzhongxin.click();//出问题的地方

//元素定位部分
/**资源中心*/
@FindBy(xpath = "//*[contains(text(),\"资源中心\")]")
public WebElement ziyuanzhongxin;
/**立即购买*/
@FindBy(xpath = "//*[contains(text(),\"立即购买\")]")
public WebElement buyButton;

程序运行的报错:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: Element <span class="mint-cell-text">...</span> is not clickable at point (35, 26). Other element would receive the click: <span class="mint-cell-mask"></span>
  (Session info: chrome=66.0.3359.126)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-4E93JJO7', ip: '192.168.1.87', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: appium.ctyun.base.AndroidTestBase.AndroidCtyunDriver
Capabilities {appActivity: com.ctg.itrdc.ecloud.module..., appPackage: com.ctg.itrdc.ecloud.test, appiumVersion: 1.9.1, browserName: , databaseEnabled: false, desired: {appActivity: com.ctg.itrdc.ecloud.module..., appPackage: com.ctg.itrdc.ecloud.test, appiumVersion: 1.9.1, browserName: , deviceName: XEGNW18315004797, locationContextEnabled: true, noReset: true, noSign: true, platformName: android, platformVersion: 8.0.0, resetKeyboard: true, unicodeKeyboard: true}, deviceManufacturer: HUAWEI, deviceModel: FLA-AL10, deviceName: XEGNW18315004797, deviceScreenSize: 1080x2160, deviceUDID: XEGNW18315004797, javascriptEnabled: true, locationContextEnabled: true, networkConnectionEnabled: true, noReset: true, noSign: true, platform: LINUX, platformName: Android, platformVersion: 8.0.0, resetKeyboard: true, takesScreenshot: true, unicodeKeyboard: true, warnings: {}, webStorageEnabled: false}
Session ID: 765bc293-9e1f-4d10-8336-0faae9193f95

appium 的 log

[JSONWP Proxy] Replacing sessionId ac6fd78372f4157c3373a0c97b639771 with 765bc293-9e1f-4d10-8336-0faae9193f95
[HTTP] <-- POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/elements 200 93 ms - 582
[HTTP]
[HTTP] --> GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95
[HTTP] {}
[W3C] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95' to command name 'getSession'
[debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95] to [GET http://127.0.0.1:8001/wd/hub/session/ac6fd78372f4157c3373a0c97b639771] with body: {}
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"ac6fd78372f4157c3373a0c97b639771\",\"status\":0,\"value\":{\"acceptInsecureCerts\":false,\"acceptSslCerts\":false,\"applicationCacheEnabled\":false,\"browserConnectionEnabled\":false,\"browserName\":\"chrome\",\"chrome\":{\"chromedriverVersion\":\"2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab)\"},\"cssSelectorsEnabled\":true,\"databaseEnabled\":false,\"handlesAlerts\":true,\"hasTouchScreen\":true,\"javascriptEnabled\":true,\"locationContextEnabled\":true,\"mobileEmulationEnabled\":false,\"nativeEvents\":true,\"pageLoadStrategy\":\"normal\",\"platform\":\"ANDROID\",\"rotatable\":false,\"setWindowRect\":false,\"takesHeapSnapshot\":true,\"takesScreenshot\":true,\"unexpectedAlertBehaviour\":\"\",\"version\":\"66.0.3359.126\",\"webStorageEnabled\":true}}"
[JSONWP Proxy] Replacing sessionId ac6fd78372f4157c3373a0c97b639771 with 765bc293-9e1f-4d10-8336-0faae9193f95
[HTTP] <-- GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95 200 6 ms - 720
[HTTP]
[HTTP] --> GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/context
[HTTP] {}
[debug] [W3C] Calling AppiumDriver.getCurrentContext() with args: ["765bc293-9e1f-4d10-8336-0faae9193f95"]
[debug] [W3C] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.ctg.itrdc.ecloud.test"
[HTTP] <-- GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/context 200 5 ms - 45
[HTTP]
[HTTP] --> GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/context
[HTTP] {}
[debug] [W3C] Calling AppiumDriver.getCurrentContext() with args: ["765bc293-9e1f-4d10-8336-0faae9193f95"]
[debug] [W3C] Responding to client with driver.getCurrentContext() result: "WEBVIEW_com.ctg.itrdc.ecloud.test"
[HTTP] <-- GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/context 200 3 ms - 45
[HTTP]
[HTTP] --> POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element
[HTTP] {"using":"xpath","value":"//*[contains(text(),\"资源中心\")]"}
[W3C] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element' to command name 'findElement'
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element] to [POST http://127.0.0.1:8001/wd/hub/session/ac6fd78372f4157c3373a0c97b639771/element] with body: {"using":"xpath","value":"//*[contains(text(),\"资源中心\")]"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ac6fd78372f4157c3373a0c97b639771","status":0,"value":{"ELEMENT":"0.08390033154710319-15"}}
[JSONWP Proxy] Replacing sessionId ac6fd78372f4157c3373a0c97b639771 with 765bc293-9e1f-4d10-8336-0faae9193f95
[HTTP] <-- POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element 200 104 ms - 108
[HTTP]
[HTTP] --> POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element/0.08390033154710319-15/click
[HTTP] {"id":"0.08390033154710319-15"}
[W3C] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element/0.08390033154710319-15/click' to command name 'click'
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element/0.08390033154710319-15/click] to [POST http://127.0.0.1:8001/wd/hub/session/ac6fd78372f4157c3373a0c97b639771/element/0.08390033154710319-15/click] with body: {"id":"0.08390033154710319-15"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ac6fd78372f4157c3373a0c97b639771","status":13,"value":{"message":"unknown error: Element <span class=\"mint-cell-text\">...</span> is not clickable at point (35, 26). Other element would receive the click: <span class=\"mint-cell-mask\"></span>\n  (Session info: chrome=66.0.3359.126)\n  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)"}}
[JSONWP Proxy] Got an unexpected response: {"sessionId":"ac6fd78372f4157c3373a0c97b639771","status":13,"value":{"message":"unknown error: Element <span class=\"mint-cell-text\">...</span> is not clickable at point (35, 26). Other element would receive the click: <span class=\"mint-cell-mask\"></span>\n  (Session info: chrome=66.0.3359.126...
[W3C] Encountered internal error running command:  {"w3cStatus":400,"jsonwp":{"sessionId":"ac6fd78372f4157c3373a0c97b639771","status":13,"value":{"message":"unknown error: Element <span class=\"mint-cell-text\">...</span> is not clickable at point (35, 26). Other element would receive the click: <span class=\"mint-cell-mask\"></span>\n  (Session info: chrome=66.0.3359.126)\n  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)"}}} ProxyRequestError: Could not proxy command to remote server. Original error: The request to /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element/0.08390033154710319-15/click has failed
[W3C]     at JWProxy.proxy (C:\Users\XXXX\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@3.14.0@appium-base-driver\lib\jsonwp-proxy\proxy.js:180:13)
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[HTTP] <-- POST /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/element/0.08390033154710319-15/click 500 295 ms - 2342
[HTTP]
[HTTP] --> GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/screenshot
[HTTP] {}
[W3C] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/screenshot' to command name 'getScreenshot'
[debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/screenshot] to [GET http://127.0.0.1:8001/wd/hub/session/ac6fd78372f4157c3373a0c97b639771/screenshot] with body: {}
[HTTP] <-- GET /wd/hub/session/765bc293-9e1f-4d10-8336-0faae9193f95/screenshot - - ms - -
[HTTP]
[JSONWP Proxy] Got an unexpected response: {"code":"ESOCKETTIMEDOUT","connect":false}
[W3C] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
[W3C]     at doJwpProxy$ (C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@2.33.0@appium-base-driver\lib\protocol\protocol.js:456:13)
[W3C]     at tryCatch (C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\node_modules\_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:67:40)
[W3C]     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\node_modules\_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:315:22)
[W3C]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\node_modules\_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:100:21)
[W3C]     at GeneratorFunctionPrototype.invoke (C:\Users\XXX\AppData\Roaming\npm\node_modules\appium\node_modules\_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:136:37)
附言 1  ·  2019年01月08日

问了下开发,这个页面的顶部 navbar 是原生的,高度大约是 210-220.
然后下面的内容是 webview 页面, 那么我切换到 webview 的时候,定位元素的高度直接丢失了 200 多(is not clickable at point (35, 26)),所有报错无法点击了。
请问这个情况怎么弄。。。。。

共收到 3 条回复 时间 点赞

可以打印下跳转后的页面是否有你点击的元素,如果没有说明跳转失败,可能是缓存原因,可以试试跳转前先杀掉 chromedriver 进程,再进行跳转

枫叶 回复

我打印了跳转后的 Pagesource 是没问题的

6楼 已删除
5楼 已删除

既然你切换了 windows_handle,page_source 也是正确的,那你就需要考虑你的定位方法是否能定位到元素了。跟顶部是不是原生的没有关系,除非你是使用坐标去定位元素的。将 webview 的页面拉到浏览器中试试,或者直接使用 chrome 的 chrome://inspect/#devices 去打开页面,用 xpath 插件定位看看。

低调 关闭了讨论 10月08日 11:08
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册