gpt4 book ai didi

ios - 如何从 EarlGrey 中的文本字段捕获/提取文本值?

转载 作者:行者123 更新时间:2023-11-29 05:14:14 24 4
gpt4 key购买 nike

我正在使用 EarlGrey 框架,我想选择整个文本并从文本字段或搜索栏中捕获它。有办法做到吗?

提前致谢!

最佳答案

您使用 XCTest API 方法提取了值。

正确的方法可以在 EarlGrey 常见问题解答中找到 https://github.com/google/EarlGrey/blob/master/docs/faq.md

// Swift
//
// Must use a wrapper class to force pass by reference in Swift 3 closures.
// inout params cannot be modified within closures. http://stackoverflow.com/a/28252105
open class Element {
var text = ""
}

/*
* Example Usage:
*
* let element = Element()
* domainField.performAction(grey_replaceText("hello.there"))
* .performAction(grey_getText(element))
*
* GREYAssertTrue(element.text != "", reason: "get text failed")
*/
public func grey_getText(_ elementCopy: Element) -> GREYActionBlock {
return GREYActionBlock.action(withName: "get text",
constraints: grey_respondsToSelector(#selector(getter: UILabel.text))) { element,
errorOrNil -> Bool in
let elementObject = element as? NSObject
let text = elementObject?.perform(#selector(getter: UILabel.text),
with: nil)?.takeRetainedValue() as? String
elementCopy.text = text ?? ""
return true
}
}

关于ios - 如何从 EarlGrey 中的文本字段捕获/提取文本值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350676/

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