目前我有:
def addInfoToStory(idOfStory, *stories)
i = -1
numOfInputs = 9
while i < numOfInputs
stories.each.with_index do |story|
$log.puts "i="+"#{i}"
$log.puts story[i]
$log.puts "i2="+"#{i}"
@browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: i+1).div.double_click
if @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: (i+=1)).div(class: "formLib1").text_field(:id, "input").set(story[i])
sleep 2
@browser.send_keys(:tab)
else @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: (i+=1)).div(class: "formLib1").select_list(:id, "select").set(story[i])
sleep 2
@browser.send_keys(:tab)
end
end
end
end
大多数信息都是textarea盒子,它可以正常工作,但是当我进入下拉列表时,该值不会改变。有什么想法吗?
答案 0 :(得分:3)
最简单的解决方案是让if语句检查是否存在文本字段或选择列表。
div_container = @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: (i+=1)).div(class: "formLib1")
if div_container.text_field(:id, "input").present?
div_container.text_field(:id, "input").set(story[i])
elsif div_container.select_list(:id, "select").present?
div_container.select_list(:id, "select").select(story[i])
end
sleep 2
@browser.send_keys(:tab)
另请注意,对于select_lists,它必须是.select
而不是.set
。
答案 1 :(得分:0)
必需
storyFields.each_index {|i|
div_container = @browser.div(id: "#{idOfStory}_firstCol").div(class: "tDetEntry", index: (i+=1)).div(class: "formLib1")
if div_container.text_field(:id, "input").present?
div_container.text_field(:id, "input").set(story[i])
elsif div_container.select_list(:id, "select").present?
div_container.select_list(:id, "select").select(story[i])
end
}
以前的答案在某种程度上有效,但没有正确循环。