Xcode UI 测试 - 如何在 WebView 中查找和点击 () 元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35442972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode UI Test - How to Find and tap() an Element Inside a WebView
提问by Audible
I am trying to find a way to tap a link with the following HTML structure:
我试图找到一种方法来点击具有以下 HTML 结构的链接:
<a>
<div id="facebook_sharing"></div>
</a>
The a
tag does not have any attributes or text associated with it, just the div
tag inside.
该a
标签没有任何与之关联的属性或文本,只有div
内部的标签。
I have tried the following but with no success:
我尝试了以下但没有成功:
app.links["facebook_sharing"].tap()
Is there a way to find the div
tag element and tap on it?
有没有办法找到div
标签元素并点击它?
Thanks!
谢谢!
回答by Joe Masilotti
Xcode UI Testing interacts with your app via accessibility. Just like it doesn't have access to the underlying UIKit elements, it doesn't have direct access to the HTML DOM. You cannot expect the framework to know about something in your markup unless that gets exposed to accessibility in some way.
Xcode UI 测试通过可访问性与您的应用程序交互。就像它不能访问底层 UIKit 元素一样,它也不能直接访问 HTML DOM。你不能指望框架知道你的标记中的某些东西,除非它以某种方式暴露给可访问性。
To "see the app as UI Testing does" open Accessibility Inspector.appon your mac. (You can easily find this by searching for it in Spotlight.) Then, hover over the div
with your cursor. If you see any of the following attributes set you can query for the element:
要“像 UI 测试一样查看应用程序”,请在Mac 上打开Accessibility Inspector.app。(您可以通过在 Spotlight 中搜索来轻松找到它。)然后,div
将光标悬停在 上。如果您看到以下任何属性集,您可以查询该元素:
accessibilityTitle
accessibilityPlaceholderValue
accessibilityLabel
accessibilityValue
accessibilityTitle
accessibilityPlaceholderValue
accessibilityLabel
accessibilityValue
If none of these are set on the a
or div
elements you should update them yourself. Think of it this way. If someone who is visually impaired uses the site, how will he/she know that he/she can interact with the Facebook link?
如果这些都没有设置在a
或div
元素上,您应该自己更新它们。这么想吧。如果视障人士使用该网站,他/她如何知道他/她可以与 Facebook 链接互动?