如何使用page-object从选择列表中选择随机选项? 我用:
def select_random_member
lstMembers = self.sltMembers_element.options.map(&:index) # getting all members from select list
lastMember = lstMembers.last
rnmMember = rand(0..lastMember)
self.sltMembers_element.options[rnmMember].click
end
我看到了获取每个选项lstMembers = self.sltEndDate_element.options.map(&:index)
*** DEPRECATION WARNING
*** You are calling a method named index at D:/members/lib/pages/members_page.rb:58:in `map'.
*** This method does not exist in page-object so it is being passed to the driver.
*** This feature will be removed in the near future.
*** Please change your code to call the correct page-object method.
*** If you are using functionality that does not exist in page-object please request it be added.
答案 0 :(得分:7)
options
方法返回一个选项元素数组。数组有一个名为sample
的内置方法,用于选择随机项。
使用sample
方法将是:
def select_random_member
sltMembers_element.options.sample.click
end
答案 1 :(得分:1)
尝试使用lstMembers
上的#sample:
def select_random_member
lstMembers = self.sltMembers_element.options.map(&:index) # getting all members from select list
self.sltEndDate_element.options[lstMembers.sample].click
end