如何在macOS中设置日期选择器的值?

时间:2017-08-25 01:10:34

标签: macos xcode-ui-testing

录制器生成以下代码,但click()始终单击年份字段。我在录制时点击了各个字段。

    let startDateDatePicker = sheetsQuery.datePickers["Start Date"]
    startDateDatePicker.click()
    startDateDatePicker.typeText("1")
    startDateDatePicker.click()
    startDateDatePicker.typeText("1")
    startDateDatePicker.click()
    startDateDatePicker.typeText("2016")

设置日期选择器UI元素的推荐方法是什么?

1 个答案:

答案 0 :(得分:1)

startDateDatePicker.dateValue = foo

编辑:既然我知道你真正想做什么,试试这个:

datePicker.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.5)).click()
datePicker.typeText("1")
datePicker.coordinate(withNormalizedOffset: CGVector(dx: 0.3, dy: 0.5)).click()
datePicker.typeText("2")
datePicker.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.5)).click()
datePicker.typeText("1934")