Appium 如何使用 Appium 绘制手势密码?求大神指导啊

Vicki · 2014年08月10日 · 最后由 yifenzhonghuxi 回复于 2016年05月19日 · 1497 次阅读

Android 现在我能两点之间的滑动,但是如果要连续绘制几个点怎么办呢?如下图这种情况,至少连续绘制 4 个点

共收到 25 条回复 时间 点赞

TouchAction(driver).press(x, y).move_to(x, y).move_to(x, y).move_to(x, y).release().perform()

Vicki #23 · 2014年08月11日 Author

#2 楼 @xuxu 非常感谢你的回答,我去试试

#2 楼 @xuxu 解决了,非常感谢

Vicki #20 · 2014年08月12日 Author

#2 楼 @xuxu
请问我要找下面导航里的东西怎么找呢?比如我要点击个人中心,跳转至个人中心页面,我怎么找到个人中心这个控件呢?

@vicki 通过 class 可以找到,使用 find_elements_by_class_name 方法,会返回包含所有相同的 class name 的元素的一个列表,再通过索引获取列表中的元素。

Vicki #18 · 2014年08月13日 Author

#7 楼 @xuxu 我试过这个方法,但是相同的 class name 元素有 43 个,我怎么知道我要找的那个的索引呢?

#7 楼 @xuxu 我有源代码,然后通过源代码的 id 去找,为什么报错提示找不到呢?

我是这样写的 driver.findElementById("tab_account");,对吗?

@vicki 不是用这里面的 id

mark,随便学习!

Vicki #12 · 2014年08月14日 Author

#10 楼 @xuxu 请问那我该怎么找呢?classname 相同的元素有太多个了,我怎么能知道我要找的是哪个呢?

#12 楼 @vicki driver.findElementByName("个人中心");

#9 楼 @vicki 你可以用你的包名:+android:id 后面除去 @+ 的值(com.android.test.app:id/tab_account),你也可以用 SDK 里面的 uiautomatorviewer.bat 去看,4.2+ 系统,root

@vicki
@xuxu xu

我也是用了这个方法
new TouchAction(driver).press(startX+ 2*stepX, startY).moveTo(startX+2*stepX, startY+ stepY).release().perform();

但是没有成功 能帮我看下什么原因吗。

debug: Responding to client with success: {"status":0,"value":null,"sessionId":"fd7369ec-e21e-49e1-8683-58e83f5990ea"}
debug: Appium request initiated at /wd/hub/session/fd7369ec-e21e-49e1-8683-58e83f5990ea/touch/perform
debug: Request received with params: {"actions":[{"options":{"x":160,"y":549},"action":"press"},{"options":{"x":560,"y":549},"action":"moveTo"}]}
debug: Pushing command to appium work queue: ["element:touchDown",{"x":160,"y":549}]
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":160,"y":549}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: touchDown
debug: Pushing command to appium work queue: ["element:touchMove",{"x":560,"y":549}]
debug: [BOOTSTRAP] [debug] Performing TouchDown using element? false x: 160, y: 549
debug: [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiDevice" to enable field "mUiAutomationBridge"
debug: [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.core.UiAutomatorBridge" to enable field "mInteractionController"
debug: [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController
debug: [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchMove","params":{"x":560,"y":549}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: touchMove
debug: [BOOTSTRAP] [debug] Performing TouchMove using element? false x: 560, y: 549

#2 楼 @xuxu 请问怎么才能滑动引导图呢,用了 swipe 函数不管用哎?

#13 楼 @kuroky 请问怎么才能滑动引导图呢,用了 swipe 函数不管用哎?

Vicki #18 · 2014年09月03日 Author

#16 楼 @pianai 我之前也是用的 swipe 也是不行,但是不知道为什么,后来我这样写的,就可以了 JavascriptExecutor js = (JavascriptExecutor) dr;
HashMap swipeObj = new HashMap();
swipeObj.put("startX", 420.0);
swipeObj.put("startY", 400.00);
swipeObj.put("endX", 30.0);
swipeObj.put("endY", 400.0);

swipeObj.put("duration", 0.4);
// 滑动
for (int i = 0; i < 3; i++) {
try {
js.executeScript("mobile: swipe", swipeObj);
} catch (WebDriverException ex) {
ex.printStackTrace();
}
}

#14 楼 @vincent 你的意思是这样写吗?dr.findElement(By.id("com.chnMicro.MFExchange:id/tab_account")).click();
这样写不行呢

#19 楼 @vicki 近期忙一直没上线。。你的不行是什么提示给出来下。。你不给我也不知道你怎么样不行。首先你确认用 SDK 里面的 uiautomatorviewer 可以看到 source-id 的属性。

#20 楼 @vincent 哦哦,uiautomatorviewer 里没有显示 source-id,我获得的那个 id 是在代码里看到的

#21 楼 @vicki 看不到可以跑么?如果不可以找一台可以看到的机器试下。。

#18 楼 @vicki 太感谢了!马上去试~

大哥们 为啥我用 Touchaction 只能点到相应的坐标点,但是不能滑动呢?

def test_gestureUnlock(self):
#time.sleep(5)
el1 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[10]")
print el1
time.sleep(2)
el2 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[13]")
print el2
time.sleep(2)
el3 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[16]")
print el3
time.sleep(2)
el4 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[17]")
print el4
time.sleep(2)
Gesture = TouchAction().press(el1).move_to(el2).move_to(el3).move_to(el4).release()
print Gesture
time.sleep(2)
Gesture.perform()

请问 手势密码这一段有什么问题啊 一直提示如下错误:

File "/Library/Python/2.7/site-packages/appium/webdriver/common/touch_action.py", line 94, in perform
self._driver.execute(Command.TOUCH_ACTION, params)
AttributeError: 'NoneType' object has no attribute 'execute'

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