Append text to text_field at watir
At watir we can submit texts to forms by such a code like : ie.text_field.set(), we could also append texts by the code such as ie.text_field.append(), following is an example:
require ‘watir’
include Watir
# Initialize the text to be submitted to a bbs
conts = []
File.open(‘goodword.txt’) do |f|
f.each_line{|l| conts << l}
end
#Initialize the advertising text to be appended
advs = []
File.open(‘adv.txt’) do |f|
f.each_line{|l| advs << l}
end
———
ie22.text_field(:name, ‘co’).set(conts[rand(conts.size)])
ie22.text_field(:name, ‘co’).append(“\n”)
ie22.text_field(:name, ‘co’).append(“\n”)
ie22.text_field(:name, ‘co’).append(“\n”)
ie22.text_field(:name, ‘co’).append(“\n”)
ie22.text_field(:name, ‘co’).append(advs[rand(advs.size)])
—–
“\n”    means change to a new line.
Good example, but I thought it is better to use:
tmp_conts = conts[rand(conts.size)] + “\n” + “\n” + “\n” + “\n” + advs[rand(advs.size)]
ie22.text_field(:name, ‘co’).set(tmp_conts)