UIAutomation with Instruments - 如何点击复制/粘贴按钮?

发布于 2024-10-25 08:05:56 字数 785 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゝ杯具 2024-11-01 08:05:56

您应该尝试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.

嘿看小鸭子会跑 2024-11-01 08:05:56

嘿。
首先,我总是使用 .elements() 而不是 .elements...但它是 JS,所以它可能正在调用分配给对象属性的函数。 .?
无论如何,也许这个编辑菜单不是应用程序的内部窗口,而是系统级菜单,当您进行拖动时会调用它?如果这是真的,请尝试:

UIATarget.localTarget().frontMostApp().elements().withName("copyButton").tap();

但正如我在 apple 中看到的那样通过调用 app.editingMenu() 引用您的版本应该没问题...
也许尝试按位置调用按钮,您会看到哪个响应:

UIATarget.localTarget().frontMostApp().editingMenu().elements()[0].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[1].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[2].tap;   

您应该通过这种方式找到正确按钮的位置。当你知道它的位置时,你可以通过 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:

UIATarget.localTarget().frontMostApp().elements().withName("copyButton").tap();

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:

UIATarget.localTarget().frontMostApp().editingMenu().elements()[0].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[1].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[2].tap;   

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.

画▽骨i 2024-11-01 08:05:56

我的做法与 yoosiba 类似,但使用了 editingMenu 元素名称。
使用 Xcode 4.5.1 和运行 iOS 6 的设备。

使用 Alex Vollmer 出色的 tuneup_js 用于目标、应用程序和 vtap( )。
否则,您可以使用 UIATarget.localTarget().frontMostApp() 和 tap()。

注意:vtap() 将延迟并重试点击。如果没有这个,您可能需要添加自己的延迟。

 // tap in textFieldA to see editingMenu.
 app.mainWindow().textFields()["textFieldA"].vtap();
 app.editingMenu().elements()["Select All"].vtap();
 app.editingMenu().elements()["Copy"].vtap();
 // must delay before attempting next tap
 target.delay(2);

 // ... navigate to different section of the app

 // tap in textFieldB to see editingMenu.
 app.mainWindow().textFields()["textFieldB"].vtap();
 // paste clipboard contents copied from textFieldA into textFieldB
 app.editingMenu().elements()["Paste"].vtap();
 target.delay(2);

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.

 // tap in textFieldA to see editingMenu.
 app.mainWindow().textFields()["textFieldA"].vtap();
 app.editingMenu().elements()["Select All"].vtap();
 app.editingMenu().elements()["Copy"].vtap();
 // must delay before attempting next tap
 target.delay(2);

 // ... navigate to different section of the app

 // tap in textFieldB to see editingMenu.
 app.mainWindow().textFields()["textFieldB"].vtap();
 // paste clipboard contents copied from textFieldA into textFieldB
 app.editingMenu().elements()["Paste"].vtap();
 target.delay(2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文