gpt4 book ai didi

ios - 如何将 accessibilityIdentifier 设置为 UIAlertController?

转载 作者:IT王子 更新时间:2023-10-29 05:15:58 27 4
gpt4 key购买 nike

这就是我如何简单地创建 UIAlertController 并将其显示在屏幕上:

private class func showAlertWithTitle(title: String, message: String) {

let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
//alert.accessibilityLabel = "my string here" //doesnt work
let action = UIAlertAction(title: "OK", style: .Default) { action in
alert.dismissViewControllerAnimated(true, completion: nil)
}

alert.addAction(action)
UIStoryboard.topViewController()?.presentViewController(alert, animated: true, completion: nil)
}

这就是我在 UITests 下访问它的方式:

emailAlert = app.alerts["First Name"] //for title "First Name"

但我想在那里设置自定义标识符并通过 firstName 访问它,如下所示:

emailAlert = app.alerts["firstName"]

这可能吗?

最佳答案

这是一个旧线程,但有人可能会使用它。

我能够像这样设置可访问性标识符:

let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.view.accessibilityIdentifier = "custom_alert"
alert.view.accessibilityValue = "\(title)-\(message)"

alert.addAction(
UIAlertAction(
title: "ALERT_BUTTON_OK".localized,
style: .default,
handler: handler
)
)

present(alert, animated: true)

这样我就可以通过可访问性标识符访问警报并在可访问性值中检查其内容。

当然它并不完美,但它确实有效 - 至少对于我使用 Appium 进行的测试而言。

关于ios - 如何将 accessibilityIdentifier 设置为 UIAlertController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com