问答 Appium-Python 通过 find_element_by_android_uiautomator 后怎么连续点击两次

傅建生 · May 05, 2018 · Last by Mr.Yang replied at December 31, 2019 · 2780 hits

Appium-Python 通过find_element_by_android_uiautomator后怎么连续点击两次,比如self.driver.find_element_by_android_uiautomator('new UiSelector().text("1")').click(),self.driver.find_element_by_android_uiautomator('new UiSelector().text("1")').click()后实际只点击了一次,log里也没有报错信息,显示两次点击成功
[HTTP] --> POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element
[HTTP] {"using":"-android uiautomator","sessionId":"3a6276af-1374-4434-8986-1877
fdab23b9","value":"new UiSelector().text(\"1\")"}
[debug] [W3C] Calling AppiumDriver.findElement() with args: ["-android uiautomat
or","new UiSelector().text(\"1\")","3a6276af-1374-4434-8986-1877fdab23b9"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class
name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8205/w
d/hub/session/d34a8178-0291-4d5d-9f2d-ba6082e480cf/element] with body: {"strateg
y":"-android uiautomator","selector":"new UiSelector().text(\"1\")","context":""
,"multiple":false}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d34a8178-0291
-4d5d-9f2d-ba6082e480cf","status":0,"value":{"ELEMENT":"7094742f-b379-4462-9ba2-
2c1e454f336d"}}
[debug] [W3C] Responding to client with driver.findElement() result: {"ELEMENT":
"7094742f-b379-4462-9ba2-2c1e454f336d"}
[HTTP] <-- POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element 200
67 ms - 122
[HTTP]
[HTTP] --> POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element/709
4742f-b379-4462-9ba2-2c1e454f336d/click
[HTTP] {"sessionId":"3a6276af-1374-4434-8986-1877fdab23b9","id":"7094742f-b379-4
462-9ba2-2c1e454f336d"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["7094742f-b379-4462-9ba2-
2c1e454f336d","3a6276af-1374-4434-8986-1877fdab23b9"]
[debug] [JSONWP Proxy] Proxying [POST /element/7094742f-b379-4462-9ba2-2c1e454f3
36d/click] to [POST http://localhost:8205/wd/hub/session/d34a8178-0291-4d5d-9f2d
-ba6082e480cf/element/7094742f-b379-4462-9ba2-2c1e454f336d/click] with body: {"e
lement":"7094742f-b379-4462-9ba2-2c1e454f336d"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d34a8178-0291
-4d5d-9f2d-ba6082e480cf","status":0,"value":true}
[debug] [W3C] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element/709
4742f-b379-4462-9ba2-2c1e454f336d/click 200 3139 ms - 76
[HTTP]
[HTTP] --> POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element
[HTTP] {"using":"-android uiautomator","sessionId":"3a6276af-1374-4434-8986-1877
fdab23b9","value":"new UiSelector().text(\"1\")"}
[debug] [W3C] Calling AppiumDriver.findElement() with args: ["-android uiautomat
or","new UiSelector().text(\"1\")","3a6276af-1374-4434-8986-1877fdab23b9"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class
name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8205/w
d/hub/session/d34a8178-0291-4d5d-9f2d-ba6082e480cf/element] with body: {"strateg
y":"-android uiautomator","selector":"new UiSelector().text(\"1\")","context":""
,"multiple":false}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d34a8178-0291
-4d5d-9f2d-ba6082e480cf","status":0,"value":{"ELEMENT":"39c31733-3d13-4c05-93a8-
8e004d0cde41"}}
[debug] [W3C] Responding to client with driver.findElement() result: {"ELEMENT":
"39c31733-3d13-4c05-93a8-8e004d0cde41"}
[HTTP] <-- POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element 200
30 ms - 122
[HTTP]
[HTTP] --> POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element/39c
31733-3d13-4c05-93a8-8e004d0cde41/click
[HTTP] {"sessionId":"3a6276af-1374-4434-8986-1877fdab23b9","id":"39c31733-3d13-4
c05-93a8-8e004d0cde41"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["39c31733-3d13-4c05-93a8-
8e004d0cde41","3a6276af-1374-4434-8986-1877fdab23b9"]
[debug] [JSONWP Proxy] Proxying [POST /element/39c31733-3d13-4c05-93a8-8e004d0cd
e41/click] to [POST http://localhost:8205/wd/hub/session/d34a8178-0291-4d5d-9f2d
-ba6082e480cf/element/39c31733-3d13-4c05-93a8-8e004d0cde41/click] with body: {"e
lement":"39c31733-3d13-4c05-93a8-8e004d0cde41"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d34a8178-0291
-4d5d-9f2d-ba6082e480cf","status":0,"value":true}
[debug] [W3C] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/3a6276af-1374-4434-8986-1877fdab23b9/element/39c
31733-3d13-4c05-93a8-8e004d0cde41/click 200 3131 ms - 76

共收到 6 条回复 时间 点赞

我没看错的话日志有click两次啊,估计间隔太长?我没记错有支持touch actions有double click方法,找一找

傅建生 #2 · May 05, 2018 作者
雨夜狂奔 回复

显示click两次是成功的但是实际界面上只有1次,triple_click = TouchAction(self.driver) triple_click.tap(element=text1, x=0, y=0, count=2)也不行

好像有时太快的话, Android本身会忽略一次点击的,我没试过双击的操作,但之前有试过打开Android设置之后点击某一个项目,总是不报错,没效果,然而使用debug模式一步步去运行的话就完全没问题,后面突然想起是不是两个操作之间太快了所以导致后一个操作做了但Android没反应,结果在打开页面与点击之间加了0.5秒的等待后就OK了,不知道这个经验对你的情况有无帮助,但也算值得参考,哈哈

这个问题我不会,
如果是固定在一个机型上测试,而且你只是想点击两次,可以试试用坐标点击。

傅建生 #5 · May 07, 2018 作者
mcgods 回复

我是在两个click之间加了sleep时间也不行.

def tap_el(self, element, times: int):
"""
单击某个控件N次
:param element: 要单击的控件
:param times: 要单击的次数
:return:
"""

def _center_rect(r):
# center_x = r['x'] + r['width'] / 2.0
# center_y = r['y'] + r['height'] / 2.0
center_x = r['width'] / 2.0
center_y = r['height'] / 2.0
return center_x, center_y

rect = element.rect
# HTNone 的设计缺陷导致不能准确的识别有效元素
# 后期可能去掉HTNone
if isinstance(rect, bool):
return

action = TouchAction(self)
center = _center_rect(element.rect)
action.tap(element=element,
x=center[0],
y=center[1],
count=times).perform()
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up