简体   繁体   English

如何以编程方式点击iOS键盘上的一点

[英]how to programmatically tap a point on the iOS keyboard

I'm using KIF to automate my app, and I'm trying to automate typing something into a UISearchBar and searching for it. 我正在使用KIF来自动化我的应用程序,并且正在尝试自动在UISearchBar键入内容并进行搜索。 Unfortunately I couldn't find a satisfactory way to do that by programmatically clicking on the search button after I've entered my search text. 不幸的是,在输入搜索文字后,以编程方式单击搜索按钮无法找到令人满意的方法

So instead, I considered simply using KIF's tapScreenAtPoint method. 因此,我只考虑使用KIF的tapScreenAtPoint方法。 The problem with that method is that it does the following: 该方法的问题在于它执行以下操作:

CGPoint windowPoint = [window convertPoint:screenPoint fromView:nil];
view = [window hitTest:windowPoint withEvent:nil];

It's expecting the tap to actually touch a view.. and since the keyboard is obviously not a view this test won't be able to trigger the search button on the keyboard. 期望水龙头实际触摸到一个视图..并且由于键盘显然不是视图,因此该测试将无法触发键盘上的搜索按钮。

How can one programmatically tap a button on the keyboard? 如何以编程方式点击键盘上的按钮? I think this would be very useful for any automation-test suite. 我认为这对于任何自动化测试套件都将非常有用。

It sounds like you're trying to tap the "Search" button in the keyboard. 听起来您正在尝试点击键盘上的“搜索”按钮。 The accessibility labels on return keys don't follow any sort of sane pattern. 返回键上的辅助功能标签不遵循任何合理的模式。 Looking in the accessibility inspector, you'll see "SEARCH" but that may not be consistent on all OS versions. 在可访问性检查器中,您会看到“ SEARCH”,但在所有操作系统版本上可能不一致。

Update 更新资料

You can trigger the search button by adding \\n to your enterText... 您可以通过在enterText...添加\\n来触发搜索按钮enterText...

[tester enterTextIntoCurrentFirstResponder:@"query\n"];

选择器中的搜索按钮

The correct way is to use: 正确的方法是使用:

[tester clearTextFromAndThenEnterText:@"sample test" intoViewWithAccessibilityLabel:@"SearchField"];

[tester waitForViewWithAccessibilityLabel:@"search"];

[tester tapViewWithAccessibilityLabel:@"search"];

Accessibility label for the return key is "search" in this case, you can verify it by using accessibility inspector app. 在这种情况下,返回键的可访问性标签为“搜索”,您可以使用可访问性检查器应用程序对其进行验证。

But be careful, the 'return key' (search/done/return/whatever) won't be pressed if you are adding a text that ends with cap letters, for example: 但是请注意,如果要添加以大写字母结尾的文本,则不会按下“返回键”(搜索/完成/返回/任何内容),例如:

"sample TEST" “样本测试”

The 'shift' button will be pressed and the 'return' button won't, even if you try to use the "tapScreenAtPoint" method. 即使您尝试使用“ tapScreenAtPoint”方法,也将按下“ shift”按钮,而不会按下“ return”按钮。

It happened to me and got me crazy for a long time until I figured out what was actually going on. 它发生在我身上,让我发疯了很长时间,直到我弄清楚到底发生了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM