Appium [已解决] appium click 事件不触发

乄動聽縼葎ヤ · 2016年08月23日 · 最后由 瑾° 回复于 2016年11月18日 · 2810 次阅读

app 封装 H5 应用,获取到了 content-desc 后 click 没有响应

a = self.driver.find_element_by_xpath('//android.view.View[contains(@content-desc,"海金社第2期")]')
      #a=self.driver.find_element_by_xpath('//android.webkit.WebView[contains(@content-desc,"投资列表")]/android.view.View[2]/android.widget.ListView[1]/android.view.View[1]')
      #print a.get_attribute('name')
      sleep(3)
      a.click()

页面布局如下

日志:


> info: <-- POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/element/1/click 200 287.994 ms - 76 {"status":0,"value":true,"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a"}
> info: --> POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/element {"using":"xpath","sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a","value":"//android.view.View[contains(@content-desc,\"娴烽噾绀剧2鏈焅")]"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.view.View[contains(@content-desc,\"娴烽噾绀剧2鏈焅")]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.view.View[contains(@content-desc,\"娴烽噾绀剧2鏈焅")]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[contains(@content-desc,"娴烽噾绀剧2鏈?)] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.view.View, INSTANCE=4]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a"}
> info: <-- POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/element 200 129.238 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a"}
> info: --> POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/element/2/click {"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a","id":"2"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"2"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a"}
> info: <-- POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/element/2/click 200 3126.151 ms - 76 {"status":0,"value":true,"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a"}
> info: --> POST /wd/hub/session/b4d7a4da-35f1-479b-a60c-195f9515fb3a/touch/perform {"sessionId":"b4d7a4da-35f1-479b-a60c-195f9515fb3a","actions":[{"action":"longPress","options":{"y":500,"x":500,"duration":500}},{"action":"release","options":{}}]}
> info: [debug] Pushing command to appium work queue: ["element:touchLongClick",{"x":500,"y":500,"duration":500}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchLongClick","params":{"x":500,"y":500,"duration":500}}

尝试了 tap 也没有效果

self.driver.tap([(500, 500), ],500)
      sleep(3)
      self.driver.tap([(400, 600), ],500)
共收到 12 条回复 时间 点赞
action = TouchAction(self.driver)
     action.press(a,400, 600).perform()

press 也没有效果

试试直接使用 adb 命令模拟事件呢?

adb input tap x, y

#1 楼 @viguss_cn 我根据经验,其实你那个点击区域也算是 1 个按键事件。触发按键事件后,在按键。
可以试试使用 findElement(By.id("resourceId")) 的方式试试,最近我在恶补 appium...

曾经遇到过你一样的问题,你可以尝试一下先滑动屏幕,然后在点击,我的理解是,打开这种 view 的界面后,下边的那一部分没有被激活,激活后就可以点击了,你可以现手动点击屏幕空白部分,手动点击前留一点时间,看看会不会 click 控件成功

#3 楼 @jiazurongyu resource-id 的内容为空,是获取不到的,

#2 楼 @darkmanno6 多谢,已按照这种方法实现

def touch(self, dx, dy):
        """
        触摸事件
        usage: touch(500, 500)
        """
        os.popen("adb shell input tap " + str(dx) + " " + str(dy))
        time.sleep(0.5)

你这个能显示 id 的是什么软件

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

#7 楼 @15502021783 uiautomatorviewer,android 自带的

这种情况在 iOS 中也会出现,但是应该怎么来实行呢?

@viguss_cn 发下具体代码吗? 或者截图
我这里也遇到这问题

我是 Win8 用的 Eclipse 写的 java

恒温 关闭了讨论 11月19日 16:32
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册