Xcode UI 测试 - 通过 id 在 Webview 中查找元素 [英] Xcode UI Testing - Finding element in Webview by id

查看:21
本文介绍了Xcode UI 测试 - 通过 id 在 Webview 中查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序是混合的,包含 webview.我正在尝试使用 Xcode UI 测试自动化我们的应用程序.我能够使用以下方法找到 Web 按钮:

Our app is hybrid and contains webview. I'm trying to automate our app using Xcode UI Testing. I was able to locate web buttons using:

let app = XCUIApplication() 
app.launch() 
let button = app.staticTexts["Button's text"]

但在我们的一项测试中,我们测试了本地化 - 这意味着文本发生变化并且静态文本查询不再有效.找不到任何关于如何通过 id(甚至类名)定位元素的文档.有任何想法吗?

But in one of our tests we test localization - meaning the text changes and the static text query is no longer valid. Couldn't find any documentation how to locate an element by his id (or even class name). Any ideas?

推荐答案

我在尝试填充 SFSafariViewController 中的文本字段时遇到了类似的问题.

I have had a similar problem trying to fill in text fields in a SFSafariViewController.

我发现使用 aria-label 属性允许我定位页面中的元素,例如

I found that using the aria-label attribute allowed me to locate elements in the page e.g.

<input role="textbox" aria-label="email" type="email" value="" name="user[email]" id="user_email">

然后在您的代码中选择该元素

And then in your code to select that element

webViewsQuery.textFields["email"]

这篇关于Xcode UI 测试 - 通过 id 在 Webview 中查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆