Appium Appium 手机 APP 测试中 Selendroid 能定位到元素,但点击该元素的时候报 An unknown server-side error

妹子文史哲 · 2015年12月09日 · 最后由 漆柒七 回复于 2018年09月17日 · 1498 次阅读

环境信息:
Appium(1.4.3)+Android(5.0)
java-client (3.0.0)


最近在做 APP 的测试,automationName 设置为Selendroid, 出现了定位到元素,但是点击元素报 An unknown server-side error

  • 使用 chrome 定位节点 -

  • 使用 Uiautomator 定位节点 -

如上图我去定位 “2 日” 这个元素,定位方式如下:

By specfied_locator = By.cssSelector(".playgo_list.days_panel>li:nth-child(2)");

点击按钮的操作:

setWebView0Context(driver, "NATIVE_APP");
setWebView0Context(driver, "WEBVIEW_0");
waitForClickabilityOf(specfied_locator);
System.out.println(driver.findElement(specfied_locator).getText());
driver.findElement(specfied_locator).click();

能定位到该元素,而且能获取元素的 text ("2 日"),但是 click 的时候报错如下:


 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 304 milliseconds
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: 'DST63159', ip: '10.32.20.128', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_60'
Session ID: f7ccd806-edda-bf47-7744-1554dc53b8a2
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{automationName=selendroid, platform=ANDROID, acceptSslCerts=true, javascriptEnabled=true, browserName=selendroid, appActivity=.home.CtripSplashActivity, networkConnectionEnabled=true, keystorePassword=CtripAndroid, rotatable=true, desired={automationName=Selendroid, app=E:\Travel\AppiumDemo\apps\product_1708167.apk,platformName=Android, deviceName=668557ed, appActivity=.home.SplashActivity, device=Android,, useKeystore=true, appPackage=test.android.view}, useKeystore=true, appPackage=ctrip.android.view, version=0.15.0, platformVersion=21, deviceName=668557ed, platformName=android, handlesAlerts=true, device=Android,, warnings={}, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
    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.RemoteWebElement.execute(RemoteWebElement.java:269)
    at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:27)
    at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
    at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:80)
    at pages.TravelDetailPage.tochooseDate(TravelDetailPage.java:42)
    at scenarios.GroupTourTest.TestStartDate(GroupTourTest.java:46)


log 日志:

info: [debug] Available contexts: WEBVIEW_0,NATIVE_APP
info: [debug] ["WEBVIEW_ctrip.android.view"]
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/window_handles","method":"GET"}
info: [debug] Available contexts: ["WEBVIEW_0","NATIVE_APP"]
info: [debug] Responding to client with success: {"status":0,"value":["WEBVIEW_0","NATIVE_APP"],"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7"}
info: <-- GET /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/contexts 200512.937 ms - 98 {"status":0,"value":["WEBVIEW_0","NATIVE_APP"],"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7"}
info: --> POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/context {"name":"WEBVIEW_0"}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: D:\allsdk\platform-tools\adb.exe -s 668557ed shell "cat /proc/net/unix"
info: [debug] WEBVIEW_20459 mapped to pid 20459
info: [debug] Getting process name for webview
info: [debug] executing cmd: D:\allsdk\platform-tools\adb.exe -s 668557ed shell "ps"
info: [debug] Parsed pid: 20459 pkg: ctrip.android.view
info: [debug] from: u0_a2470,20459,326,2388404,295048,ffffffff,00000000,S,ctrip.android.view
info: [debug] returning process name: ctrip.android.view
info: [debug] Available contexts: WEBVIEW_0,NATIVE_APP
info: [debug] ["WEBVIEW_ctrip.android.view"]
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/window_handles","method":"GET"}
info: [debug] Available contexts: ["WEBVIEW_0","NATIVE_APP"]
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/context","method":"POST","json":{
"name":"WEBVIEW_0"}}
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7"}
info: <-- POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/context 200428.880 ms - 76 {"status":0,"value":null,"sessionId":"8dd54ef5-ff4b-713d-6944-64
44645e99a7"}
info: --> POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element {"using":"css selector","value":".playgo_list.days_panel>li:nth-child(2)"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element","method":"POST","json":{
"using":"css selector","value":".playgo_list.days_panel>li:nth-child(2)"}}
info: [debug] Proxied response received with status 200: {"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7","status":0,"value":{"ELEMENT":":wdc:1449713052433"}
}
info: <-- POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element 20097.199 ms - 104
info: --> GET /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/displayed {}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/di
splayed","method":"GET"}
info: [debug] Proxied response received with status 200: {"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7","status":0,"value":true}
info: <-- GET /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/displayed 200 122.695 ms - 76
info: --> GET /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/enabled {}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/en
abled","method":"GET"}
info: [debug] Proxied response received with status 200: {"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7","status":0,"value":true}
info: <-- GET /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/enabled 200 56.363 ms - 76
info: --> POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element {"using":"css selector","value":".playgo_list.days_panel>li:nth-child(2)"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element","method":"POST","json":{
"using":"css selector","value":".playgo_list.days_panel>li:nth-child(2)"}}
info: [debug] Proxied response received with status 200: {"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7","status":0,"value":{"ELEMENT":":wdc:1449713052433"}
}
info: <-- POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element 20072.969 ms - 104
info: --> POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/click {"id":":wdc:1449713052433"}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/cl
ick","method":"POST","json":{"id":":wdc:1449713052433"}}
info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue"
:"CATCH_ALL: java.lang.NumberFormatException: Invalid int: \"61.1875\"\n\tat 
java.lang.Integer.invalidInt(Integer.java:138)\n\tat java.lang.Integer.parse(Integer.java:410)\n\tat
 java.lang.Integer.parseInt(Integer.java:367)\n\tat
 java.lang.Integer.parseInt(Integer.java:334)\n\tat
 io.selendroid.server.model.AndroidWebElement.getCenterCoordinates(AndroidWebElement.java:233)\n\tat 
io.selendroid.server.model.AndroidWebElement.click(AndroidWebElement.java:249)\n\tat
io.selendroid.server.handler.ClickElement.safeHandle(ClickElement.java:36)\n\tat
io.selendroid.server.handler.SafeRequestHandler.handle(SafeRequestHandler.java:87)\n\tat
io.selendroid.server.AndroidServlet.handleRequest(AndroidServlet.java:264)\n\tat 
io.selendroid.server.common.BaseServlet.handleHttpRequest(BaseServlet.java:67)\n\tat
io.selendroid.server.common.http.ServerHandler.channelRead(ServerHandler.java:53)\n\tat
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)\n\tat
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)\n\tat
io.netty.handler.traffic.AbstractTrafficShapingHandler.channelRead(AbstractTrafficShapingHandler.java:223)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)\n\tat
io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)\n\tat
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:148)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)\n\tat 
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:430)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:384)\n\tat
io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)\n\tat
io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)\n\tat java.lang.Thread.run(Thread.java:818)\n"},"sessionId":"8dd54ef5-ff4b-713d-6944-6444645e99a7"}
info: <-- POST /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7/element/%3Awdc%3A1449713052433/click 500 250.163 ms - 3111
info: --> DELETE /wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7 {}
info: Shutting down appium session
info: [debug] Stopping selendroid server
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/8dd54ef5-ff4b-713d-6944-6444645e99a7","method":"DELETE"}
info: [debug] executing cmd: D:\allsdk\platform-tools\adb.exe -s 668557ed shell "am force-stop ctrip.android.view"

已经排查,页面加载完毕,而且元素只有一个,现在没有好的解决方案
这个问题已经困扰一个礼拜了,绝不是伸手党 ,恳请大神帮忙看下!!!

哪位大神能帮忙解决下这个问题

共收到 25 条回复 时间 点赞

以下几种情况的帖子可能会进入此节点:

标题/正文描述不清不楚;
无意义的发帖;
存在广告嫌疑;
招聘信息描述不清楚,未按照招聘节点的要求发帖,或职位信息不符合社区 用户群需求;
新注册的帐号发布产品推广贴是不允许的哦,付出和回报是相等的,当然如果你的产品确实非常有意思,或是和测试有关的东西,是不会进入这个栏目的。
如果你发现你的帖子到了此节点下面,请自我检查反省,并修改帖子内容。

新人请阅读:https://testerhome.com/topics/982
学会如何合理提问,请阅读:https://testerhome.com/topics/587

当你修改好以后,可以回帖 @lihuazhang@seveniruby@monkey 等人,我们将会审核,通过以后才可恢复到其他节点。

@lihuazhang@seveniruby@monkey 能帮忙看下这个问题吗

@monkey @lihuazhang @seveniruby 已经修改好排版, 麻烦帮忙看下问题

setWebView0Context
waitForClickabilityO
是什么?

和 click 前那四句有关的 log 呢?

#5 楼 @sanlengjingvv 就是将 setWebView0Context 的方法是在 webview 和 native 之间转换 waitForClickabilityO 是等待页面加载,确认元素已经出现 ,log 日志我已经贴上了 帮忙看下

AndroidWebElement.java:233 行,可能是 selendroid 的问题。

int xSize = (new Double(result[0])).intValue();
 int ySize = (new Double(result[1])).intValue();
 return new Point(topLeft.x + xSize / 2, topLeft.y+ ySize / 2);

用 js 点行吗

WebElement element =  driver.findElement("");
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);

#9 楼 @sanlengjingvv 尝试了下

js.executeScript("arguments[0].click();", specfied_locator );

没有报错, 但也没有点击到这个元素

#8 楼 @lihuazhang 这个方法之前试验过 只能获取元素在弹框的坐标 还要获取弹框的坐标 想问下还有其他的简单直接的方法吗

#11 楼 @tobe_nb 我看了下官方的代码 貌似不会出现你这个问题 今年五月份已经修复了这个 bug

—— 来自 TesterHome 官方 安卓客户端

13 楼 @seveniruby 我之前也没有碰到这个问题,现在是启动 Appium,pom 文件中是 java—client 是版本是 3.0, 难道版本还不够高

#14 楼 @tobe_nb
selendroid 在 appium server 端。
1.4.14 升级到最新的 Selendroid 0.17

此文甚好 容我细品

#14 楼 @tobe_nb 升级 appium 即可. 貌似他新版本包括了 selendroid 的最新版本

#17 楼 @seveniruby 我已经将 Appium 升级到 1.4.16 ,但是 rerun 的时候仍报上面的那个错误,在 build/selendroid 的目录下,查看到

https://github.com/selendroid/selendroid/blob/master/pom.xml 是 0.18 是不是要更新到最新版的 selenroid

楼主, 你问题解决了吗?我也遇到了和你一样的问题。不过我试 mac 版本的。测试 ios。选取相册中 “提取” 按钮。mac 版本好像最高才 1.4.13.。。。

http://www.cnblogs.com/fnng/p/3288444.html 这个帖子解决了我的问题。

#20 楼 @cl_baozi 你的 appiumserver 也报这样的错吗 你是 ActionChains(driver).double_click(qqq).perform() 解决的? 我明日试下

楼主是携程的啊?
能吐个槽吗,携程买火车票提前支付,结果没抢到还提前自己退款了,是什么鬼啊。

@tobe_nb 是的,反正每次报 An unknown server-side error 我就用 ActionChains(driver).context_click(z).perform() 就解决了(关键字:mac,ios,appium,python)
我的源码:

import unittest
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from Package import Sign
from time import sleep
class account(unittest.TestCase):

    def chaxun(self):
        try:
            driver = Sign.fzl.denglu(self)#获取登陆

            driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATabBar[1]/UIAButton[3]').click()#点击银联商户

            driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]/UIAButton[3]').click()#点击对账报表


            z = driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATextField[1]')#点击开始时间
            ActionChains(driver).context_click(z).perform()

uiautomator 获取页面元素中文乱码,机型安卓 5.0.2,请问能解决吗

请问楼主这个问题解决了吗,我也遇到了相同问题,很困扰啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册