点击绝对坐标 [英] Tap on absolute coordinates

查看:41
本文介绍了点击绝对坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试点击使用视图实例化的自定义 NavigationBar.由于我似乎无法先选择它然后点击,我想使用自定义坐标执行点击(元素在左上角):

I'm trying to perform a tap on custom NavigationBar that is instantiated with a view. As I seem to be not able to select it first and then tap, I wanted to perform a tap using custom coordinates (element is in the upper left corner):

UIATarget.localTarget().frontMostApp().tapWithOptions({tapCount: 1, touchCount: 1, duration: 0.1, tapOffset: {x: 0, y: 0});

不幸的是,点击 (0,0) 的原点看起来就在 NavigationBar 元素的正下方,我无法点击该元素,因为它位于 NavigationBar 内部.从屏幕左上角开始执行点击的正确方法是什么?

Unfortunately it looks that the origin of the tap (0,0) is right below the NavigationBar element and I'm not able to tap on this element as it's inside the NavigationBar. What's the proper way to perform a tap starting from the upper left corner of the screen?

推荐答案

我认为在 tapWithOptions 的选项中指定 duration 键是导致问题的原因.

I think that specifying the duration key in the options for tapWithOptions is what is causing the problem.

在我使用 UI 自动化测试的一个应用中,我尝试了一项实验.我粘贴了您在 Instruments 中编写的行,但在运行时不起作用.但是当我删除 duration 键时,它起作用了,并且执行了一个水龙头.我的猜测是,即使持续时间很短,添加 duration 也会以某种方式触发点击并按住"手势.点击手势识别器显然忽略了 UI 自动化生成的这些类型的事件.通过删除 duration 键,UI 自动化执行正常点击,它应该可以工作.

In one of my own apps that I test with UI Automation, I tried an experiment. I pasted the line you wrote in Instruments and it didn't work when I ran it. But when I removed the duration key, it worked and a tap was performed. My guess is that adding duration somehow triggers a "tap and hold" gesture even though the duration is very short. The tap gesture recognizers apparently ignore these kinds of events generated by UI Automation. By removing the duration key, UI Automation performs a normal tap and it should work.

这篇关于点击绝对坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆