0

我在 iOS 应用程序上有一个 UIPickerView。尝试使用 calabash-ios 在 UIPickerView 上向下滚动到特定值。这是一份年表。

我试过这个,看看它是否至少会滚动:

    Then I scroll down on "myPickerAccessibilityLabel"

没用

UIPickerView 是否有自定义步骤?

4

2 回答 2

1

你应该可以使用类似的东西

然后我将选择器上的日期更改为“2016”

基于对另一个 SO Calabash 的回复:Select a date from a UIDatePickerview

于 2015-06-03T20:55:12.517 回答
0

Lasse 的回答是正确的(我投了赞成票)。但为了清楚起见,它只适用于 UIDatePickers。我只是在查看 Calabash iOS 源代码,看起来我们已经将一些选择器方法标记为私有。以下是从荆棘宝石中抓取的。它使用私有 UIKit 选择器来操纵选择器轮。需要注意的是,它可能不适用于非圆形(无限)选择器。

您可以使用下面的代码编写一个步骤,将选择器列滚动到带有文本的行。

def picker_current_index_for_column (column)
  arr = query('pickerTableView', :selectionBarRow)
  arr[column]
end
# methods common to generic and date pickers
def picker_current_index_for_column_is(column, val)
  picker_current_index_for_column(column) == val
end

def previous_index_for_column (column)
  picker_current_index_for_column(column) - 1
end

def picker_next_index_for_column (column)
  picker_current_index_for_column(column) + 1
end

def picker_scroll_down_on_column(column)
  new_row = previous_index_for_column column
  query("pickerTableView index:'#{column}'", [{:selectRow => new_row},
                                              {:animated => 1},
                                              {:notify => 1}])
end

def picker_scroll_up_on_column(column)
  new_row = picker_next_index_for_column column
  query("pickerTableView index:'#{column}'", [{:selectRow => new_row},
                                              {:animated => 1},
                                              {:notify => 1}])
end
def visible_titles (column)
  query("pickerTableView index:#{column} child pickerTableViewWrapperCell", :wrappedView, :text).reverse
end

# May only work on circular pickers - does _not_ work on non-circular
# pickers because the visible titles do _not_ follow the selected index
def selected_title_for_column (column)
  selected_idx = picker_current_index_for_column column
  titles = visible_titles column
  titles[selected_idx]
end

def scroll_picker(dir, column)
  if dir.eql? 'down'
    picker_scroll_down_on_column column
  else
    picker_scroll_up_on_column column
  end
  sleep 0.4
end
于 2015-06-04T12:54:06.167 回答