问题
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});
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?
回答1:
I think that specifying the duration key in the options for tapWithOptions is what is causing the problem.
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.
来源:https://stackoverflow.com/questions/14738389/tap-on-absolute-coordinates