我是XCUITESTING的新手,这是我的代码
let btn = UIButton(frame: CGRect(x: 0, y: 5, width: 50, height: 40))
btn.addTarget(self, action: #selector(addEmail), for: .touchDown)
btn.setImage(UIImage(named: "f_add_email"), for: .normal)
btn.contentMode = .center
btn.isAccessibilityElement = true
btn.accessibilityIdentifier = "emailsbutton"
txtField.isAccessibilityElement = true
txtField.accessibilityIdentifier = "emailtextbox"
txtField.rightViewMode = .always
txtField.rightView = btn
我能够像XCUIApplication()。textFields [“ emailtextbox”]一样访问我的文本框
但是,如果我使用XCUIApplication()。textFields [“ emailsbutton”]则会引发错误
答案 0 :(得分:0)
按钮可能在textField下。如果是这样,则需要使用以下代码进行访问:
XCUIApplication().textFields.buttons["emailsbutton"]
答案 1 :(得分:0)
我认为您应该尝试以下操作:
1)始终XCUIApplication().debugDescription
看到该按钮的ID /标签/标题。
您可以使用按钮或其他元素来触发对其的点击。
XCUIApplication().buttons["emailsbutton"].tap()
OR
XCUIApplication().otherElements["emailsbutton"].tap()