UIAutomation with Instruments - 如何点击复制/粘贴按钮?
我正在使用 Instruments for iOS 自动化,但我似乎不知道如何点击复制/粘贴菜单上的选项。当我执行 logElementTree() 时,我看到我们返回一个 UIEditingMenu,然后返回三个元素(对应于该菜单的选项,例如复制/粘贴等)。我试图将其放入一个变量中,然后尝试“点击”该变量,但我无法让它工作。这是我的代码示例:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
//This generates the highlighted text
app.dragInsideWithOptions({startOffset:{x:0.45, y:0.6}, endOffset:{x:0.45, y:0.6}, duration:1.5});
var copy = app.editingMenu.elements.withName("copyButton");
copy.tap();
Instruments returns, "0) UIAElementNil". In addition to the above, I've also tried:
app.elements.withName("copyButton")
window.elements.withName("copyButton")
因此,我可以使用编辑菜单来生成可用选项,但我无法找到点击或选择其中一个选项的方法。我不太确定我知道如何开始引用这些选项。
有人有什么想法吗?
谢谢!
I'm using Instruments for iOS automation and I can't seem to figure out how to tap options on the copy/paste menu. When I do a logElementTree(),I see that we are returning a UIEditingMenu and then three elements (which correspond to options of that menu, such as copy/paste, etc..). I am attempting to place this into a variable, and then trying to "tap" that variable but I cannot get that to work. Here is a sample of my code:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
//This generates the highlighted text
app.dragInsideWithOptions({startOffset:{x:0.45, y:0.6}, endOffset:{x:0.45, y:0.6}, duration:1.5});
var copy = app.editingMenu.elements.withName("copyButton");
copy.tap();
Instruments returns, "0) UIAElementNil". In addition to the above, I've also tried:
app.elements.withName("copyButton")
window.elements.withName("copyButton")
So, I can get the editingMenu to produce the available options, but I cannot figure out a way to tap or select one of those options. I'm not quite sure I know how to reference those options to begin with.
Does anyone have any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该尝试
app.editingMenu().elements()[index].tap()
,其中index是您想要从返回的元素数组中点击的选项的索引。我的一个就这样工作了。You should try
app.editingMenu().elements()[index].tap()
where index is the index of the option you want to tap from the array of elements returned. I got my one working this way.嘿。
首先,我总是使用
.elements()
而不是.elements
...但它是 JS,所以它可能正在调用分配给对象属性的函数。 .?无论如何,也许这个编辑菜单不是应用程序的内部窗口,而是系统级菜单,当您进行拖动时会调用它?如果这是真的,请尝试:
但正如我在 apple 中看到的那样通过调用
app.editingMenu()
引用您的版本应该没问题...也许尝试按位置调用按钮,您会看到哪个响应:
您应该通过这种方式找到正确按钮的位置。当你知道它的位置时,你可以通过
button.logElement();
检查它的属性。有了这个 inf,您应该能够切换回.withName
方法而不是硬编码位置。Hey.
First of all, I was always using
.elements()
not.elements
... but it is JS, so it may be invoking function that is assigned to object property..?Anyway, maybe this edit menu is not internal window of the app, but it is system level menu, that is invoked, when you do the drag? If that is true, try:
But as I see in apple reference your version with calling
app.editingMenu()
should be fine...Maybe try calling buttons by position, and you will see which respond:
You should find position of correct one this way. When you have it's position you can check its properties by
button.logElement();
. With this inf you you should be able to switch back to.withName
method instead hardcoded position.我的做法与 yoosiba 类似,但使用了 editingMenu 元素名称。
使用 Xcode 4.5.1 和运行 iOS 6 的设备。
使用 Alex Vollmer 出色的 tuneup_js 用于目标、应用程序和 vtap( )。
否则,您可以使用 UIATarget.localTarget().frontMostApp() 和 tap()。
注意:vtap() 将延迟并重试点击。如果没有这个,您可能需要添加自己的延迟。
I did this similar to yoosiba but with editingMenu element names.
Using Xcode 4.5.1 and device running iOS 6.
Using Alex Vollmer's excellent tuneup_js for target, app and vtap().
Otherwise you can use UIATarget.localTarget().frontMostApp() and tap().
NOTE: vtap() will delay and retry tapping. Without this you may need to add your own delays.