我正试图利用违约铁路日期、时间和日间田与Capybara建立日期选择。 我使用了within
方法,为外地找到选定箱子,但当我使用xPath来寻找正确的箱子时,它便留下了>随附在<<>>/code>范围内,并在该元件的网页上发现了第一起。
这里是我使用的法典。 我正在对网页进行2个时段的测试,但我只能因这一错误而改变第1页。 此时,我有一只 d干的 container箱,清理了时日现场,但我确实计划改用标签找到该代码。
module Marketron
module DateTime
def select_date(field, options = {})
date_parse = Date.parse(options[:with])
year = date_parse.year.to_s
month = date_parse.strftime( %B )
day = date_parse.day.to_s
within("div##{field}") do
find(:xpath, "//select[contains(@id, "_#{FIELDS[:year]}")]").select(year)
find(:xpath, "//select[contains(@id, "_#{FIELDS[:month]}")]").select(month)
find(:xpath, "//select[contains(@id, "_#{FIELDS[:day]}")]").select(day)
end
end
def select_time(field, options = {})
require "time"
time_parse = Time.parse(options[:with])
hour = time_parse.hour.to_s.rjust(2, 0 )
minute = time_parse.min.to_s.rjust(2, 0 )
within("div##{field}") do
find(:xpath, "//select[contains(@id, "_#{FIELDS[:hour]}")]").find(:xpath, "option[contains(@value, #{hour} )]").select_option
find(:xpath, "//select[contains(@id, "_#{FIELDS[:minute]}")]").find(:xpath, "option[contains(@value, #{minute} )]").select_option
end
end
def select_datetime(field, options = {})
select_date(field, options)
select_time(field, options)
end
private
FIELDS = {year: "1i", month: "2i", day: "3i", hour: "4i", minute: "5i"}
end
end
World(Marketron::DateTime)