Appium WebView 的滚动翻页问题

shimazakiharuka · 2014年08月11日 · 最后由 咸鱼 回复于 2018年05月22日 · 1800 次阅读

1.怎么换社区头像?
2.WebView 中有 XPath 可以获得指定元素,但是貌似安卓的情况,即便可以获得当前网页的所有元素的 xpath,但是当前页看不到的元素,即便获得,点击后也没有反应。但是 ios 的情况下,通过 xpath,会自动滚动屏幕到该元素。为什么安卓不能,那么我该用什么函数滚动屏幕?是设置问题,还是本来这俩函数就不一样,求大神指导。

共收到 21 条回复 时间 点赞

问题 1:修改头像在页面右上角,点开昵称里有个个人资料设置,在个人资料设置页面有修改头像
问题 2:滚动操作可以参考这个帖子 http://testerhome.com/topics/1132

@xiaomayi0323 请问 swipe 报错如何解决?

debug: [BOOTSTRAP] [debug] Swiping from [x=100.0, y=800.0] to [x=100.0, y=200.0] with steps: 840
debug: [BOOTSTRAP] [debug] Returning result: {"value":"The swipe did not complete successfully","status":13}
debug: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"The swipe did not complete successfully"},"sessionId":"d3b8b595-2b60-4f13-a5c2-c99106ac403a"}

@xiaomayi0323
info: --> POST /wd/hub/session/64d0aa9c-71a0-43e1-bccf-065ccccebc72/touch/perform {"actions":[{"action":"press","options":{"y":800,"x":100}},{"action":"wait","options":{"ms":3000}},{"action":"moveTo","options":{"y":200,"x":100}},{"action":"release","options":{}}]}
debug: Pushing command to appium work queue: ["swipe",{"startX":100,"startY":800,"endX":100,"endY":200,"steps":84}]
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":100,"startY":800,"endX":100,"endY":200,"steps":84}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: swipe
debug: [BOOTSTRAP] [debug] Swiping from [x=100.0, y=800.0] to [x=100.0, y=200.0] with steps: 84
debug: [BOOTSTRAP] [debug] Returning result: {"value":"The swipe did not complete successfully","status":13}
debug: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"The swipe did not complete successfully"},"sessionId":"64d0aa9c-71a0-43e1-bccf-065ccccebc72"}
info: <-- POST /wd/hub/session/64d0aa9c-71a0-43e1-bccf-065ccccebc72/touch/perform 500 2454.481 ms - 208
info: --> DELETE /wd/hub/session/64d0aa9c-71a0-43e1-bccf-065ccccebc72 {}
info: Shutting down appium session

#7 楼 @liu 模拟器?还是真机?建议用真机试试

#9 楼 @liu 哦,Swipe 部分的代码也让我看看

@xiaomayi0323 手机信息:
info: <-- GET /wd/hub/session/64d0aa9c-71a0-43e1-bccf-065ccccebc72 200 1.080 ms - 641 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"4.2","platformName":"Android","deviceName":"ZTE","browserName":"","appActivity":"com.netease.nr.biz.ad.AdActivity","appPackage":"com.netease.newsreader.activity"},"platformName":"Android","deviceName":"ZTE","appActivity":"com.netease.nr.biz.ad.AdActivity","appPackage":"com.netease.newsreader.activity"},"sessionId":"64d0aa9c-71a0-43e1-bccf-065ccccebc72"}

@xiaomayi0323
@Test
public void netnews() throws InterruptedException{
driver.swipe(100,800,100,200,3000);
List text = driver.findElement(By.className("android.widget.ListView")).findElements(By.className("android.widget.LinearLayout"));
text.get(5).click();
Thread.sleep(6000);
driver.sendKeyEvent(4);
WebElement text2 = driver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.TextView\").text(\"娱乐\")");
text2.click();
Thread.sleep(1000);
driver.swipe(100,800,100,200,3000);
List text3 = driver.findElement(By.className("android.widget.ListView")).findElements(By.className("android.widget.LinearLayout"));
text3.get(5).click();
Thread.sleep(6000);
}

#13 楼 @liu 你要从上滑到下面?

@xiaomayi0323 恩,我想进去应用以后,先向下滑动

@xiaomayi0323 如果把 swipe 函数注释掉,代码可以运行。但是加上 swipe 函数,一运行就直接推出,或者有时候可以向下滑动,但是还是会报错,导致程序退出。

#16 楼 @liu 加上 swipe 函数,一运行就直接退出,那是因为出错了啊

@xiaomayi0323 仔细看了你给的网页,终于解决了问题。swipe 对 android 4.2 可能不兼容,我换了一台 4.3 的机器后,可以正常运行了。
感谢你帮助。

#19 楼 @liu 不用谢,解决问题就好,同时记录好这个坑,能总结并 share 出来就更好

我是安卓 7.1.2,安卓 4.3 都报那样的错误 真的是滑动不兼容这些版本么

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