移动测试基础 AttributeError: 'WebElement' object has no attribute 'swipe'

万万 · 2016年09月18日 · 最后由 ChelseaZhang 回复于 2017年06月16日 · 2085 次阅读

刚接触 iOS 自动化测试,参考网上的经验一步步摸索,目前在尝试用 Python 编写自动化测试脚本测试 APP UI 相关功能。现在想进行删除设备的操作,其操作步骤和 QQ 中删除和某一对象会话的步骤一样:选中对象,向左滑一小步,然后点击滑动后出现的删除按钮,即可删除。对于左滑操作,我用的是 swipe,代码如下:

def choice_TheDevice(driver):
        if driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]').is_displayed():
            el = driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]')
            el.swipe(150,108,90,108)      
            sleep(3)
报错为
AttributeError: 'WebElement'  object has no attribute 'swipe'

在执行这个函数前,已经 Sleep 了足够的时间,swipe 中的坐标都是绝对坐标,且没有超出对应控件滑动范围。在 testcase 里也进行了 webdriver 的导入:

from selenium import webdriver
from appium import webdriver

Appium log 如下:
[debug] [UIAuto] Socket data received (6359 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"UIAApplication":{"@":{"name":"campus","label":"campus","value":null,"dom":null,"enabled":true,"valid":true,"visible":true,"hint":null,"path":"/0","x":0,"y":0,"width":375,"height":667},">":[{"UIAWindow":{"@":{"name":null,"label":null,"value":null,"dom":null,"enabled":true,"valid
[debug] [UIAuto] Sending command to instruments: au.getElementByIndexPath('/0/0/3/0')

[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Got new command 63 from instruments: au.getElementByIndexPath('/0/0/3/0')

[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: evaluating au.getElementByIndexPath('/0/0/3/0')
2016-09-18 05:17:17 +0000 Debug: evaluation finished
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Lookup returned [object UIATableCell] with the name "我的设备" (id: 16).
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: responding with:
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Running system command #64: /Volumes/Appium/Appium.app/Contents/Resources/node/bin/node /Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-uiauto/build/lib/bin/command-proxy-client.js /var/folders/tf/89068tvn199bhwpk5r3hg03h0000gn/T/instruments_sock 2,{"status":...

[debug] [UIAuto] Socket data received (39 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"ELEMENT":"16"}}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"16"}
[HTTP] <-- POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/element 200 2185 ms - 88
[HTTP] --> POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/appium/app/close {"sessionId":"4af2e2fb-8c7a-4cd0-bfcd-72764252b2db"}
[MJSONWP] Calling AppiumDriver.closeApp() with args: ["4af2e2fb-8c7a-4cd0-bfcd-7...
[debug] [iOS] Executing iOS command 'closeApp'
[debug] [UIAuto] Destroying instruments client socket.
[debug] [UIAuto] Closing socket server.
[debug] [UIAuto] Instruments socket server was closed
[debug] [Instruments] Starting shutdown.
[debug] [Instruments] Sending sigterm to instruments
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Stopped: Script was stopped by the user

[debug] [Instruments] [INST STDERR] 2016-09-17 22:17:17.661 instruments[4896:58240] Attempting to change event horizon while disengage

[debug] [Instruments] [INST] Instruments Trace Complete (Duration : 132.406662s; Output : /var/folders/tf/89068tvn199bhwpk5r3hg03h0000gn/T/appium-instruments/instrumentscli0.trace)

[debug] [Instruments] Instruments exited with code 0
[debug] [iOSLog] Stopping iOS log capture
[iOS] Successfully closed the [/Users/wanqingyao/Desktop/campus.app] app.
[MJSONWP] Responding to client with driver.closeApp() result: null
[HTTP] <-- POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/appium/app/close 200 1922 ms - 76
[HTTP] --> DELETE /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["4af2e2fb-8c7a-4cd0-bfcd-7...
[debug] [iOS] Deleting ios session
[debug] [iOS] Running ios sim reset flow
[debug] [iOS] Killing the simulator
[debug] [iOSSim] Killing all iOS Simulators

我在想出现这个报错是不是因为测试框架版本的原因(之前通过 find_element_by_name 查找元素各种报错,后来才知道新版本的 Appium 已经取消了通过 name 查找元素这个方法),现把版本信息贴出如下:
version:
VMware12.1.1
os x 10.11.6
xcode 7.1 beta
appium 1.5.3
python2.7
node-v4.4.7

看了各种类似问题的帖子,上面的解决办法都尝试过了也无法解决问题。求各位大神指导,感激不尽!

共收到 14 条回复 时间 点赞

控件的属性不支持滑动

为啥要from selenium import webdriver

为什么要 from selenium import webdriver?python 里面乱导入包,默认的指定会被替换掉,建议删掉此行

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

我觉得是应该使用 flick 吧

10.flick
flick(self, start_x, start_y, end_x, end_y):

Flick from one point to another point.
    按住A点后快速滑动至B点
    :Args:
     - start_x - x-coordinate at which to start
     - start_y - y-coordinate at which to start
     - end_x - x-coordinate at which to stop
     - end_y - y-coordinate at which to stop

    :Usage:
        driver.flick(100, 100, 100, 400)

用法 driver.flick(x1,y1,x2,y2)

#4 楼 @xinxjxjxj flick 也之前试过了,不行,报相同的错误

#3 楼 @lingcizhisheng 这一行有和没有,结果是一样的。我也是看了其他帖子后加上了这一句,结果没什么用。

#1 楼 @jackie TableCell 不支持滑动的吗?手工测试的时候是可以滑动的呀

#2 楼 @sanlengjingvv 我也是看了别人的帖子,https://testerhome.com/topics/3885,然后发现加了这句后没用

#7 楼 @wanwan001 报错的意思就是控件没有 swipe 属性,可能控件包了几层,你没有能获取到可以滑动的那一层吧

万万 #10 · 2016年09月23日 Author

#9 楼 @jackie 好的 明白你的意思了,我试试 谢谢

我的 swipe 一直滑动不了(采用的是 RF+Appium),提示:Responding to client that a method is not implemented

通过在 node_modules\appium\lib\server 的 controller.js 文件发现 mobileCmdMap 里面根本就没有 swipe 方法,对了,我的 Appium 是 window 版本 1.4.16.1

于是我退而求其次,想用 flick,但又发现 AppiumLibrary 这个测试库里面没有 flick 这个关键字,请问有大神知道怎么解决吗?
现在滑动这个问题卡住我一周时间了。

万万 #12 · 2016年09月30日 Author

#11 楼 @JasonChiang 我也试了大神们提供的各种解决办法,问题依然存在;并且现在遇到了升级 Appium 的新问题,头大呀

这个问题我已经解决了,需要扩展 RF 的关键字,弃用了官方的 swipe。

我也遇到了这个问题,楼主解决该问题了吗

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